summaryrefslogtreecommitdiffstats
path: root/lib/options.cc
blob: 84474c660652e4958bfa74398a7a6917484b71e4 (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
/* KPilot
**
** Copyright (C) 2000-2001 by Adriaan de Groot
** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
**
** This is a file of odds and ends, with debugging functions and stuff.
*/

/*
** 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 "options.h"


#include <iostream>

#include <tqsize.h>

#include <kconfig.h>
#include <kdebug.h>
#include <kcmdlineargs.h>

#ifdef DEBUG
int debug_level = 1;
#else
int debug_level = 0;
#endif

// The daemon also has a debug level; debug_spaces is 60 spaces,
// to align FUNCTIONSETUP output. The one byte extra is for the NUL.
//
//
static const char debug_spaces[61] =
	"                    "
	"                    "
	"                    ";


TQString rtExpand(const TQString &s, TQt::TextFormat richText)
{
	if (richText == TQt::RichText)
	{
		TQString t(s);
		return t.replace(CSL1("\n"), CSL1("<br/>\n"));
	}
	else
	{
		return s;
	}

}

TQDateTime readTm(const struct tm &t)
{
	TQDateTime dt;
	dt.setDate(TQDate(1900 + t.tm_year, t.tm_mon + 1, t.tm_mday));
	dt.setTime(TQTime(t.tm_hour, t.tm_min, t.tm_sec));
	return dt;
}



struct tm writeTm(const TQDateTime &dt)
{
	struct tm t;

	t.tm_wday = 0; // unimplemented
	t.tm_yday = 0; // unimplemented
	t.tm_isdst = 0; // unimplemented
#ifdef HAVE_STRUCT_TM_TM_ZONE
	t.tm_zone = 0; // unimplemented
#endif

	t.tm_year = dt.date().year() - 1900;
	t.tm_mon = dt.date().month() - 1;
	t.tm_mday = dt.date().day();
	t.tm_hour = dt.time().hour();
	t.tm_min = dt.time().minute();
	t.tm_sec = dt.time().second();

	return t;
}



struct tm writeTm(const TQDate &d)
{
	TQDateTime dt(d);
	return writeTm(dt);
}

KPilotDepthCount::KPilotDepthCount(int, int level, const char *s) :
	fDepth(depth),
	fLevel(level),
	fName(s)
{
	DEBUGKPILOT << "! DEPRECATED Depth call.\n!   "
		<< kdBacktrace(4) << endl;

	if (debug_level>=fLevel)
	{
		DEBUGKPILOT << indent() << ">" << name() << endl;
	}
	depth++;
}

KPilotDepthCount::KPilotDepthCount(int level, const char *s) :
	fDepth(depth),
	fLevel(level),
	fName(s)
{
	if (debug_level>=fLevel)
	{
		DEBUGKPILOT << indent() << ">" << name() << endl;
	}
	depth++;
}

KPilotDepthCount::~KPilotDepthCount()
{
	depth--;
	std::cerr.clear(std::ios_base::goodbit);
}

const char *KPilotDepthCount::indent() const
{
	if (fDepth < 30)
	{
		return debug_spaces + 60-fDepth*2;
	}
	else
	{
		return debug_spaces;
	}
}

int KPilotDepthCount::depth = 0;