kpilot

memofiles.h

Go to the documentation of this file.
00001 #ifndef _MEMOFILE_MEMOFILES_H
00002 #define _MEMOFILE_MEMOFILES_H
00003 /* memofiles.h          KPilot
00004 **
00005 ** Copyright (C) 2004-2007 by Jason 'vanRijn' Kasper
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU Lesser General Public License as published by
00011 ** the Free Software Foundation; either version 2.1 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU Lesser General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU Lesser General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 #include "plugin.h"
00030 #include <qmap.h>
00031 
00032 #include "memofile.h"
00033 
00034 typedef QMap<int, QString> MemoCategoryMap;
00035 
00036 class Memofile;
00037 
00038 class Memofiles {
00039 
00040 public:
00041 
00042     Memofiles (MemoCategoryMap & categories, PilotMemoInfo &appInfo, 
00043         QString & baseDirectory, CUDCounter &fCtrHH);
00044     ~Memofiles();
00045 
00046     void load(bool loadAll);
00047     void save();
00048     void eraseLocalMemos();
00049     void setPilotMemos (QPtrList<PilotMemo> & memos);
00050     void addModifiedMemo (PilotMemo * memo);
00051     void deleteMemo (PilotMemo * memo);
00052 
00053     bool isFirstSync();
00054     bool isReady() { return _ready; };
00055 
00056     QPtrList<Memofile> getModified();
00057     QPtrList<Memofile> getAll() { return _memofiles; } ;
00058     Memofile * find (const QString & category, const QString & filename);
00059     Memofile * find (recordid_t id);
00060 
00061     MemoCategoryMap readCategoryMetadata();
00062     void setCategories(MemoCategoryMap map) { _categories = map; } ;
00063 
00064     static QString FIELD_SEP;
00065     static QString sanitizeName(QString name);
00066 
00067     int count() { return _memofiles.count(); }
00068 
00069 private:
00070 
00071     MemoCategoryMap _categories;
00072     PilotMemoInfo &_memoAppInfo;
00073     QString & _baseDirectory;
00074     CUDCounter &_cudCounter;
00075     QPtrList<Memofile> _memofiles;
00076 
00077     bool  loadFromMetadata();
00078     bool  ensureDirectoryReady();
00079     bool  checkDirectory(QString & dir);
00080     bool  saveMemoMetadata();
00081     bool  saveCategoryMetadata();
00082     bool  saveMemos();
00083     bool  folderRemove(const QDir & dir);
00084 
00085     QString filename(PilotMemo * memo);
00086 
00087 
00088     QString _categoryMetadataFile;
00089     QString _memoMetadataFile;
00090 
00091     bool _metadataLoaded;
00092     bool _ready;
00093 
00094 };
00095 #endif //MEMOFILES_H
00096