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

knotes

  • sources
  • kde-4.12
  • kdepim
  • knotes
  • resource
resourcelocal.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  This file is part of KNotes.
3 
4  Copyright (c) 2004, Bo Thorsen <bo@sonofthor.dk>
5  2004-2006, Michael Brade <brade@kde.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  MA 02110-1301, USA.
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the Qt library by Trolltech AS, Norway (or with modified versions
25  of Qt that use the same license as Qt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  Qt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 *******************************************************************/
33 
34 #include "knotes/resource/resourcelocal.h"
35 #include "knotes/resource/resourcelocalconfig.h"
36 #include "knotes/resource/resourcemanager.h"
37 #include "knotes/resource/resourcenotes.h"
38 
39 #include <klocale.h>
40 #include <kmessagebox.h>
41 #include <kstandarddirs.h>
42 #include <kconfiggroup.h>
43 
44 #include <kcal/icalformat.h>
45 
46 
47 ResourceLocal::ResourceLocal()
48  : ResourceNotes(), mCalendar( QString::fromLatin1( "UTC" ) )
49 {
50  kDebug( 5500 ) << "ResourceLocal::ResourceLocal()";
51  setType( QLatin1String("file") );
52  mURL = KUrl::fromPath( KGlobal::dirs()->saveLocation( "data", QLatin1String("knotes/") ) +
53  QLatin1String("notes.ics") );
54 }
55 
56 ResourceLocal::ResourceLocal( const KConfigGroup &group )
57  : ResourceNotes( group ), mCalendar( QString::fromLatin1( "UTC" ) )
58 {
59  kDebug( 5500 ) << "ResourceLocal::ResourceLocal()";
60  setType( QLatin1String("file") );
61  mURL = KUrl::fromPath( KGlobal::dirs()->saveLocation( "data", QLatin1String("knotes/") ) +
62  QLatin1String("notes.ics") );
63 
64  const KUrl u = group.readPathEntry( "NotesURL", QString() );
65  if ( !u.isEmpty() ) {
66  mURL = u;
67  }
68 }
69 
70 ResourceLocal::~ResourceLocal()
71 {
72 }
73 
74 void ResourceLocal::writeConfig( KConfigGroup &group )
75 {
76  KRES::Resource::writeConfig( group );
77  group.writePathEntry( "NotesURL", mURL.prettyUrl() );
78 }
79 
80 bool ResourceLocal::load()
81 {
82  mCalendar.load( mURL.toLocalFile() );
83 
84  KCal::Journal::List notes = mCalendar.journals();
85  KCal::Journal::List::ConstIterator it;
86  KCal::Journal::List::ConstIterator end(notes.constEnd());
87  for ( it = notes.constBegin(); it != end; ++it ) {
88  manager()->registerNote( this, *it );
89  }
90 
91  return true;
92 }
93 
94 bool ResourceLocal::save()
95 {
96  if ( !mCalendar.save( mURL.toLocalFile(), new KCal::ICalFormat() ) ) {
97  KMessageBox::error( 0, i18n( "<qt>Unable to save the notes to <b>%1</b>. "
98  "Check that there is sufficient disk space."
99  "<br />There should be a backup in the same "
100  "directory though.</qt>", mURL.toLocalFile() ) );
101  return false;
102  }
103 
104  return true;
105 }
106 
107 bool ResourceLocal::addNote( KCal::Journal *journal )
108 {
109  return mCalendar.addJournal( journal );
110 }
111 
112 bool ResourceLocal::deleteNote( KCal::Journal *journal )
113 {
114  return mCalendar.deleteJournal( journal );
115 }
116 
117 KCal::Alarm::List ResourceLocal::alarms( const KDateTime &from, const KDateTime &to )
118 {
119  KCal::Alarm::List alarms;
120  KCal::Journal::List notes = mCalendar.journals();
121  KCal::Journal::List::ConstIterator note;
122 
123  for ( note = notes.constBegin(); note != notes.constEnd(); ++note ) {
124  KDateTime preTime = from.addSecs( -1 );
125  KCal::Alarm::List::ConstIterator it;
126  KCal::Alarm::List::ConstIterator itEnd(( *note )->alarms().constEnd());
127  for( it = ( *note )->alarms().constBegin(); it != itEnd; ++it ) {
128  if ( ( *it )->enabled() ) {
129  KDateTime dt = ( *it )->nextRepetition( preTime );
130  if ( dt.isValid() && dt <= to ) {
131  alarms.append( *it );
132  }
133  }
134  }
135  }
136 
137  return alarms;
138 }
ResourceLocal::ResourceLocal
ResourceLocal()
Definition: resourcelocal.cpp:47
ResourceLocal::load
virtual bool load()
Load resource data.
Definition: resourcelocal.cpp:80
ResourceLocal::writeConfig
virtual void writeConfig(KConfigGroup &group)
Definition: resourcelocal.cpp:74
resourcenotes.h
resourcelocal.h
resourcelocalconfig.h
ResourceLocal::alarms
virtual KCal::Alarm::List alarms(const KDateTime &from, const KDateTime &to)
Definition: resourcelocal.cpp:117
ResourceLocal::save
virtual bool save()
Save resource data.
Definition: resourcelocal.cpp:94
ResourceLocal::~ResourceLocal
virtual ~ResourceLocal()
Definition: resourcelocal.cpp:70
ResourceLocal::mCalendar
KCal::CalendarLocal mCalendar
Definition: resourcelocal.h:73
ResourceLocal::addNote
virtual bool addNote(KCal::Journal *)
Definition: resourcelocal.cpp:107
resourcemanager.h
ResourceNotes
This class provides the interfaces for a KNotes resource.
Definition: resourcenotes.h:54
ResourceLocal::mURL
KUrl mURL
Definition: resourcelocal.h:74
ResourceNotes::manager
KNotesResourceManager * manager() const
Definition: resourcenotes.cpp:56
ResourceLocal::deleteNote
virtual bool deleteNote(KCal::Journal *)
Definition: resourcelocal.cpp:112
KNotesResourceManager::registerNote
void registerNote(ResourceNotes *resource, KCal::Journal *journal)
Definition: resourcemanager.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal