kpilot

options.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2000-2001 by Adriaan de Groot
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This is a file of odds and ends, with debugging functions and stuff.
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 
00034 #include <iostream>
00035 
00036 #include <qsize.h>
00037 
00038 #include <kconfig.h>
00039 #include <kdebug.h>
00040 #include <kcmdlineargs.h>
00041 
00042 #ifdef DEBUG
00043 int debug_level = 1;
00044 #else
00045 int debug_level = 0;
00046 #endif
00047 
00048 // The daemon also has a debug level; debug_spaces is 60 spaces,
00049 // to align FUNCTIONSETUP output. The one byte extra is for the NUL.
00050 //
00051 //
00052 static const char debug_spaces[61] =
00053     "                    "
00054     "                    "
00055     "                    ";
00056 
00057 
00058 QString rtExpand(const QString &s, Qt::TextFormat richText)
00059 {
00060     if (richText == Qt::RichText)
00061     {
00062         QString t(s);
00063         return t.replace(CSL1("\n"), CSL1("<br/>\n"));
00064     }
00065     else
00066     {
00067         return s;
00068     }
00069 
00070 }
00071 
00072 QDateTime readTm(const struct tm &t)
00073 {
00074     QDateTime dt;
00075     dt.setDate(QDate(1900 + t.tm_year, t.tm_mon + 1, t.tm_mday));
00076     dt.setTime(QTime(t.tm_hour, t.tm_min, t.tm_sec));
00077     return dt;
00078 }
00079 
00080 
00081 
00082 struct tm writeTm(const QDateTime &dt)
00083 {
00084     struct tm t;
00085 
00086     t.tm_wday = 0; // unimplemented
00087     t.tm_yday = 0; // unimplemented
00088     t.tm_isdst = 0; // unimplemented
00089 #ifdef HAVE_STRUCT_TM_TM_ZONE
00090     t.tm_zone = 0; // unimplemented
00091 #endif
00092 
00093     t.tm_year = dt.date().year() - 1900;
00094     t.tm_mon = dt.date().month() - 1;
00095     t.tm_mday = dt.date().day();
00096     t.tm_hour = dt.time().hour();
00097     t.tm_min = dt.time().minute();
00098     t.tm_sec = dt.time().second();
00099 
00100     return t;
00101 }
00102 
00103 
00104 
00105 struct tm writeTm(const QDate &d)
00106 {
00107     QDateTime dt(d);
00108     return writeTm(dt);
00109 }
00110 
00111 KPilotDepthCount::KPilotDepthCount(int, int level, const char *s) :
00112     fDepth(depth),
00113     fLevel(level),
00114     fName(s)
00115 {
00116     DEBUGKPILOT << "! DEPRECATED Depth call.\n!   "
00117         << kdBacktrace(4) << endl;
00118 
00119     if (debug_level>=fLevel)
00120     {
00121         DEBUGKPILOT << indent() << ">" << name() << endl;
00122     }
00123     depth++;
00124 }
00125 
00126 KPilotDepthCount::KPilotDepthCount(int level, const char *s) :
00127     fDepth(depth),
00128     fLevel(level),
00129     fName(s)
00130 {
00131     if (debug_level>=fLevel)
00132     {
00133         DEBUGKPILOT << indent() << ">" << name() << endl;
00134     }
00135     depth++;
00136 }
00137 
00138 KPilotDepthCount::~KPilotDepthCount()
00139 {
00140     depth--;
00141     std::cerr.clear(std::ios_base::goodbit);
00142 }
00143 
00144 const char *KPilotDepthCount::indent() const
00145 {
00146     if (fDepth < 30)
00147     {
00148         return debug_spaces + 60-fDepth*2;
00149     }
00150     else
00151     {
00152         return debug_spaces;
00153     }
00154 }
00155 
00156 int KPilotDepthCount::depth = 0;
00157