kpilot

memofile.h

Go to the documentation of this file.
00001 #ifndef _MEMOFILE_MEMOFILE_H
00002 #define _MEMOFILE_MEMOFILE_H
00003 /* memofile.h           KPilot
00004 **
00005 ** Copyright (C) 2004-2007 by Jason 'vanRijn' Kasper
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 Lesser General Public License as published by
00012 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU Lesser 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 
00031 #include "options.h"
00032 
00033 // Only include what we really need:
00034 // First UNIX system stuff, then std C++,
00035 // then Qt, then KDE, then local includes.
00036 //
00037 //
00038 
00039 #include <time.h>  // required by pilot-link includes
00040 
00041 #include <pi-memo.h>
00042 
00043 #include <qfile.h>
00044 #include <qdir.h>
00045 #include <qtextstream.h>
00046 #include <qtextcodec.h>
00047 
00048 #include "pilotMemo.h"
00049 
00050 #include "memofiles.h"
00051 
00055 class Memofile : public PilotMemo
00056 {
00057     public:
00058         Memofile(PilotMemo * memo, QString categoryName, QString fileName, QString baseDirectory);
00059         Memofile(recordid_t id, int category, uint lastModifiedTime, uint size, QString categoryName, QString filename, QString baseDirectory);
00060         Memofile(int category, QString categoryName, QString fileName, QString baseDirectory);
00061 
00062         uint lastModified() const { return _lastModified; } ;
00063         uint size() const { return _size; } ;
00064 
00065         void setModifiedByPalm(bool mod) { _modifiedByPalm = mod; } ;
00066         void setModified(bool modified) { _modified = modified; } ;
00067 
00068         bool isModified(void);
00069         bool isModifiedByPalm() { return _modifiedByPalm; } ;
00070         bool isLoaded(void) { return (! text().isEmpty()); } ;
00071         bool isNew(void) { return _new; } ;
00072 
00073         bool load();
00074 
00075         bool fileExists() { return QFile::exists(filenameAbs()); } ;
00076 
00077         void setID(recordid_t id);
00078 
00079         bool save();
00080         bool deleteFile();
00081 
00082         QString toString() {
00083             return CSL1("id: [") + QString::number(id())
00084                     + CSL1("], category:[") + _categoryName
00085                     + CSL1("], filename: [") + _filename + CSL1("]");
00086         } ;
00087         const QString & getCategoryName() { return _categoryName; } ;
00088         const QString & getFilename() { return _filename; } ;
00089         const QString & filename() { return _filename; } ;
00090 
00091     private:
00092         bool saveFile();
00093         bool isModifiedByTimestamp();
00094         bool isModifiedBySize();
00095 
00096         QString filenameAbs() { return dirName() + filename(); } ;
00097         QString dirName() { return _baseDirectory + QDir::separator() + _categoryName + QDir::separator(); } ;
00098         bool setCategory(const QString &label);
00099         uint getFileLastModified();
00100         uint getFileSize();
00101 
00102         bool _modifiedByPalm;
00103         bool _modified;
00104         bool _new;
00105         uint _lastModified;
00106         uint _size;
00107 
00108         QString _categoryName;
00109         QString _filename;
00110         QString _baseDirectory;
00111 } ;
00112 
00113 #endif