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

ktimetracker

  • sources
  • kde-4.12
  • kdepim
  • ktimetracker
kttcalendar.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by Sérgio Martins <iamsergio@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the
16  * Free Software Foundation, Inc.
17  * 51 Franklin Street, Fifth Floor
18  * Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #include "kttcalendar.h"
23 
24 #include <KCalCore/FileStorage>
25 #include <KCalCore/MemoryCalendar>
26 #include <KCalCore/ICalFormat>
27 
28 #include <KDateTime>
29 #include <KDirWatch>
30 #include <KDebug>
31 
32 using namespace KCalCore;
33 using namespace KTimeTracker;
34 
35 class KTTCalendar::Private {
36 public:
37  Private( const QString &filename ) : m_filename( filename )
38  {
39  }
40  QString m_filename;
41  QWeakPointer<KTTCalendar> m_weakPtr;
42  KCalCore::FileStorage::Ptr m_fileStorage;
43 };
44 
45 KTTCalendar::KTTCalendar( const QString &filename,
46  bool monitorFile ) : KCalCore::MemoryCalendar( KDateTime::LocalZone )
47  , d( new Private( filename ) )
48 {
49  if ( monitorFile ) {
50  connect( KDirWatch::self(), SIGNAL(dirty(QString)), SIGNAL(calendarChanged()) );
51  if ( !KDirWatch::self()->contains( filename ) ) {
52  KDirWatch::self()->addFile( filename );
53  }
54  }
55 }
56 
57 KTTCalendar::~KTTCalendar()
58 {
59  delete d;
60 }
61 
62 bool KTTCalendar::reload()
63 {
64  deleteAllTodos();
65  KTTCalendar::Ptr calendar = weakPointer().toStrongRef();
66  KCalCore::FileStorage::Ptr fileStorage = FileStorage::Ptr( new FileStorage( calendar,
67  d->m_filename,
68  new ICalFormat() ) );
69  const bool result = fileStorage->load();
70  if ( !result )
71  kError() << "KTTCalendar::reload: problem loading calendar";
72  return result;
73 }
74 
75 QWeakPointer<KTTCalendar> KTTCalendar::weakPointer() const
76 {
77  return d->m_weakPtr;
78 }
79 
80 void KTTCalendar::setWeakPointer(const QWeakPointer<KTTCalendar> &ptr )
81 {
82  d->m_weakPtr = ptr;
83 }
84 
86 KTTCalendar::Ptr KTTCalendar::createInstance( const QString &filename, bool monitorFile )
87 {
88  KTTCalendar::Ptr calendar( new KTTCalendar( filename, monitorFile ) );
89  calendar->setWeakPointer( calendar.toWeakRef() );
90  return calendar;
91 }
92 
94 bool KTTCalendar::save()
95 {
96  KTTCalendar::Ptr calendar = weakPointer().toStrongRef();
97  FileStorage::Ptr fileStorage = FileStorage::Ptr( new FileStorage( calendar,
98  d->m_filename,
99  new ICalFormat() ) );
100 
101  const bool result = fileStorage->save();
102  if ( !result )
103  kError() << "KTTCalendar::save: problem saving calendar";
104  return result;
105 }
KTimeTracker::KTTCalendar
Definition: kttcalendar.h:29
KTimeTracker::KTTCalendar::save
bool save()
reimp
Definition: kttcalendar.cpp:94
KTimeTracker::KTTCalendar::reload
bool reload()
reimp
Definition: kttcalendar.cpp:62
KTimeTracker::KTTCalendar::Ptr
QSharedPointer< KTimeTracker::KTTCalendar > Ptr
Definition: kttcalendar.h:32
KTimeTracker::KTTCalendar::createInstance
static KTimeTracker::KTTCalendar::Ptr createInstance(const QString &filename, bool monitorFile)
Creates a new KTTCalendar and calls KTTCalendar::setWeakPointer(), so we can do KTTCalendar::Ptr ptr ...
Definition: kttcalendar.cpp:86
KTimeTracker::KTTCalendar::setWeakPointer
void setWeakPointer(const QWeakPointer< KTimeTracker::KTTCalendar > &)
Definition: kttcalendar.cpp:80
KTimeTracker::KTTCalendar::weakPointer
QWeakPointer< KTimeTracker::KTTCalendar > weakPointer() const
Definition: kttcalendar.cpp:75
kttcalendar.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

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

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