summaryrefslogtreecommitdiffstats
path: root/lib/options.h
blob: d8dcc0c4c519c7a45e0d66a14305ed394873b674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef _KPILOT_OPTIONS_H
#define _KPILOT_OPTIONS_H
/* options.h			KPilot
**
** Copyright (C) 1998-2001,2002,2003 by Dan Pilone
** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
**
** This file defines some global constants and macros for KPilot.
** In particular, KDE2 is defined when KDE2 seems to be the environment
** (is there a better way to do this?). Use of KDE2 to #ifdef sections
** of code is deprecated though.
**
** Many debug functions are defined as well.
*/

/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2.1 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/

#include "config.h"

#include <tqglobal.h>
#include <tqnamespace.h>
#include <tqstring.h>

#include <kdebug.h>
#include <tdeversion.h>
#include <klocale.h>

#if !(KDE_IS_VERSION(3,4,0))
#error "This is KPilot for (really) KDE 3.5 and won't compile with KDE < 3.4.0"
#endif

#if !(KDE_IS_VERSION(3,5,0))
#warning "This is KPilot for KDE 3.5 and might not compile with KDE < 3.5.0"
#endif

#include "pilotLinkVersion.h"

#include <iostream>

using namespace std;
inline std::ostream& operator <<(std::ostream &o, const TQString &s)
	{ if (s.isEmpty()) return o<<"<empty>"; else return o<<s.latin1(); }
inline std::ostream& operator <<(std::ostream &o, const TQCString &s)
	{ if (s.isEmpty()) return o<<"<empty>"; else return o << *s; }


#ifndef NDEBUG
#define DEBUG	(1)
#endif

extern KDE_EXPORT int debug_level;

class KDE_EXPORT KPilotDepthCount
{
public:
	KPilotDepthCount(int, int level, const char *s);
	KPilotDepthCount(int level, const char *s);
	~KPilotDepthCount();
	const char *indent() const;
	inline const char *name() const { return fName; } ;
	inline int level() const { return fLevel; } ;

protected:
	static int depth;
	int fDepth;
	int fLevel;
	const char *fName;
} ;


#ifdef DEBUG
#ifdef __GNUC__
#define KPILOT_FNAMEDEF(l)	KPilotDepthCount fname(l,__FUNCTION__)
#else
#define	KPILOT_FNAMEDEF(l)	KPilotDepthCount fname(l,__FILE__ ":" "__LINE__")
#endif

#define FUNCTIONSETUP		KPILOT_FNAMEDEF(1)
#define FUNCTIONSETUPL(l)	KPILOT_FNAMEDEF(l)

// stderr / iostream-based debugging.
//
//
#define DEBUGKPILOT   std::cerr
#define WARNINGKPILOT std::cerr.clear(std::ios_base::goodbit),\
	std::cerr << "! " << k_funcinfo << std::endl << "!   "




inline std::ostream& operator <<(std::ostream &o, const KPilotDepthCount &d)
{
	if (debug_level >= d.level())
	{
		o.clear(std::ios_base::goodbit);
		return o << d.indent() << ' ' << d.name();
	}
	else
	{
		o.setstate(std::ios_base::badbit | std::ios_base::failbit);
		return o;
	}
}

#else

// no debugging at all
//
#define DEBUGSTREAM   kndbgstream
#define DEBUGKPILOT   kndDebug()
#define WARNINGKPILOT kndDebug()

// With debugging turned off, FUNCTIONSETUP doesn't do anything.
//
//
#define FUNCTIONSETUP const int fname = 0; Q_UNUSED(fname);
#define FUNCTIONSETUPL(a) const int fname = a; Q_UNUSED(fname);
#endif

#define KPILOT_VERSION	"4.9.4-3510 (elsewhere)"


// Function to expand newlines in rich text to <br>\n
TQString rtExpand(const TQString &s, TQt::TextFormat richText);



/**
 * Convert a struct tm from the pilot-link package to a TQDateTime
 */
KDE_EXPORT TQDateTime readTm(const struct tm &t);
/**
 * Convert a TQDateTime to a struct tm for use with the pilot-link package
 */
KDE_EXPORT struct tm writeTm(const TQDateTime &dt);
KDE_EXPORT struct tm writeTm(const TQDate &dt);


// Some layout macros
//
// SPACING is a generic distance between visual elements;
// 10 seems reasonably good even at high resolutions.
//
//
#define SPACING		(10)

// Semi-Standard safe-free expression. Argument a may be evaluated more
// than once though, so be careful.
//
//
#define KPILOT_FREE(a)	{ if (a) { ::free(a); a=0L; } }
#define KPILOT_DELETE(a) { if (a) { delete a; a=0L; } }


// This marks strings that need to be i18n()ed in future,
// but cannot be done now due to message freeze. The _P
// variant is to handle plurals and is wrong, but unavoidable.
//
//
#define TODO_I18N(a)	TQString::fromLatin1(a)
#define TODO_I18N_P(a,b,c) ((c>1) ? a : b)

// Handle some cases for TQT_NO_CAST_ASCII and NO_ASCII_CAST.
// Where possible in the source, known constant strings in
// latin1 encoding are marked with CSL1(), to avoid gobs
// of latin1() or fromlatin1() calls which might obscure
// those places where the code really is translating
// user data from latin1.
//
// The extra "" in CSL1 is to enforce that it's only called
// with constant strings.
//
//
#define CSL1(a)		TQString::fromLatin1(a "")

#endif