kpilot

options.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_OPTIONS_H
00002 #define _KPILOT_OPTIONS_H
00003 /* options.h            KPilot
00004 **
00005 ** Copyright (C) 1998-2001,2002,2003 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 **
00008 ** This file defines some global constants and macros for KPilot.
00009 ** In particular, KDE2 is defined when KDE2 seems to be the environment
00010 ** (is there a better way to do this?). Use of KDE2 to #ifdef sections
00011 ** of code is deprecated though.
00012 **
00013 ** Many debug functions are defined as well.
00014 */
00015 
00016 /*
00017 ** This program is free software; you can redistribute it and/or modify
00018 ** it under the terms of the GNU Lesser General Public License as published by
00019 ** the Free Software Foundation; either version 2.1 of the License, or
00020 ** (at your option) any later version.
00021 **
00022 ** This program is distributed in the hope that it will be useful,
00023 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00025 ** GNU Lesser General Public License for more details.
00026 **
00027 ** You should have received a copy of the GNU Lesser General Public License
00028 ** along with this program in a file called COPYING; if not, write to
00029 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00030 ** MA 02110-1301, USA.
00031 */
00032 
00033 /*
00034 ** Bug reports and questions can be sent to kde-pim@kde.org
00035 */
00036 
00037 #include "config.h"
00038 
00039 #include <qglobal.h>
00040 #include <qnamespace.h>
00041 #include <qstring.h>
00042 
00043 #if (QT_VERSION < 0x030300)
00044 #error "This is KPilot for KDE3.5 and won't compile with Qt < 3.3.0"
00045 #endif
00046 
00047 #include <kdebug.h>
00048 #include <kdeversion.h>
00049 #include <klocale.h>
00050 
00051 #if !(KDE_IS_VERSION(3,4,0))
00052 #error "This is KPilot for (really) KDE 3.5 and won't compile with KDE < 3.4.0"
00053 #endif
00054 
00055 #if !(KDE_IS_VERSION(3,5,0))
00056 #warning "This is KPilot for KDE 3.5 and might not compile with KDE < 3.5.0"
00057 #endif
00058 
00059 #include "pilotLinkVersion.h"
00060 
00061 #include <iostream>
00062 
00063 using namespace std;
00064 inline std::ostream& operator <<(std::ostream &o, const QString &s)
00065     { if (s.isEmpty()) return o<<"<empty>"; else return o<<s.latin1(); }
00066 inline std::ostream& operator <<(std::ostream &o, const QCString &s)
00067     { if (s.isEmpty()) return o<<"<empty>"; else return o << *s; }
00068 
00069 
00070 #ifndef NDEBUG
00071 #define DEBUG   (1)
00072 #endif
00073 
00074 extern KDE_EXPORT int debug_level;
00075 
00076 class KDE_EXPORT KPilotDepthCount
00077 {
00078 public:
00079     KPilotDepthCount(int, int level, const char *s);
00080     KPilotDepthCount(int level, const char *s);
00081     ~KPilotDepthCount();
00082     const char *indent() const;
00083     inline const char *name() const { return fName; } ;
00084     inline int level() const { return fLevel; } ;
00085 
00086 protected:
00087     static int depth;
00088     int fDepth;
00089     int fLevel;
00090     const char *fName;
00091 } ;
00092 
00093 
00094 #ifdef DEBUG
00095 #ifdef __GNUC__
00096 #define KPILOT_FNAMEDEF(l)  KPilotDepthCount fname(l,__FUNCTION__)
00097 #else
00098 #define KPILOT_FNAMEDEF(l)  KPilotDepthCount fname(l,__FILE__ ":" "__LINE__")
00099 #endif
00100 
00101 #define FUNCTIONSETUP       KPILOT_FNAMEDEF(1)
00102 #define FUNCTIONSETUPL(l)   KPILOT_FNAMEDEF(l)
00103 
00104 // stderr / iostream-based debugging.
00105 //
00106 //
00107 #define DEBUGKPILOT   std::cerr
00108 #define WARNINGKPILOT std::cerr.clear(std::ios_base::goodbit),\
00109     std::cerr << "! " << k_funcinfo << std::endl << "!   "
00110 
00111 
00112 
00113 
00114 inline std::ostream& operator <<(std::ostream &o, const KPilotDepthCount &d)
00115 {
00116     if (debug_level >= d.level())
00117     {
00118         o.clear(std::ios_base::goodbit);
00119         return o << d.indent() << ' ' << d.name();
00120     }
00121     else
00122     {
00123         o.setstate(std::ios_base::badbit | std::ios_base::failbit);
00124         return o;
00125     }
00126 }
00127 
00128 #else
00129 
00130 // no debugging at all
00131 //
00132 #define DEBUGSTREAM   kndbgstream
00133 #define DEBUGKPILOT   kndDebug()
00134 #define WARNINGKPILOT kndDebug()
00135 
00136 // With debugging turned off, FUNCTIONSETUP doesn't do anything.
00137 //
00138 //
00139 #define FUNCTIONSETUP const int fname = 0; Q_UNUSED(fname);
00140 #define FUNCTIONSETUPL(a) const int fname = a; Q_UNUSED(fname);
00141 #endif
00142 
00143 #define KPILOT_VERSION  "4.9.4-3510 (elsewhere)"
00144 
00145 
00146 // Function to expand newlines in rich text to <br>\n
00147 QString rtExpand(const QString &s, Qt::TextFormat richText);
00148 
00149 
00150 
00154 KDE_EXPORT QDateTime readTm(const struct tm &t);
00158 KDE_EXPORT struct tm writeTm(const QDateTime &dt);
00159 KDE_EXPORT struct tm writeTm(const QDate &dt);
00160 
00161 
00162 // Some layout macros
00163 //
00164 // SPACING is a generic distance between visual elements;
00165 // 10 seems reasonably good even at high resolutions.
00166 //
00167 //
00168 #define SPACING     (10)
00169 
00170 // Semi-Standard safe-free expression. Argument a may be evaluated more
00171 // than once though, so be careful.
00172 //
00173 //
00174 #define KPILOT_FREE(a)  { if (a) { ::free(a); a=0L; } }
00175 #define KPILOT_DELETE(a) { if (a) { delete a; a=0L; } }
00176 
00177 
00178 // This marks strings that need to be i18n()ed in future,
00179 // but cannot be done now due to message freeze. The _P
00180 // variant is to handle plurals and is wrong, but unavoidable.
00181 //
00182 //
00183 #define TODO_I18N(a)    QString::fromLatin1(a)
00184 #define TODO_I18N_P(a,b,c) ((c>1) ? a : b)
00185 
00186 // Handle some cases for QT_NO_CAST_ASCII and NO_ASCII_CAST.
00187 // Where possible in the source, known constant strings in
00188 // latin1 encoding are marked with CSL1(), to avoid gobs
00189 // of latin1() or fromlatin1() calls which might obscure
00190 // those places where the code really is translating
00191 // user data from latin1.
00192 //
00193 // The extra "" in CSL1 is to enforce that it's only called
00194 // with constant strings.
00195 //
00196 //
00197 #define CSL1(a)     QString::fromLatin1(a "")
00198 
00199 #endif