Vidalia  0.2.15
tcglobal.cpp
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file tcglobal.cpp
00013 ** \brief Provides common methods and constants used by the torcontrol library
00014 */
00015 
00016 #include "tcglobal.h"
00017 
00018 
00019 namespace tc {
00020 
00021 /* Creates a new message using <b>fmt</b> and a severity level of
00022  * QtDebugMsg. */
00023 DebugMessage
00024 debug(const QString &fmt)
00025 {
00026   return DebugMessage(QtDebugMsg, fmt);
00027 }
00028 
00029 /* Creates a new message using <b>fmt</b> and a severity level of
00030  * QtWarningMsg. */
00031 DebugMessage
00032 warn(const QString &fmt)
00033 {
00034   return DebugMessage(QtWarningMsg, fmt);
00035 }
00036 
00037 /* Creates a new message using <b>fmt</b> and a severity level of
00038  * QtCriticalMsg. */
00039 DebugMessage
00040 error(const QString &fmt)
00041 {
00042   return DebugMessage(QtCriticalMsg, fmt);
00043 }
00044 
00045 /* Creates a new message using <b>fmt</b> and a severity level of
00046  * QtFatalMsg. */
00047 DebugMessage
00048 fatal(const QString &fmt)
00049 {
00050   return DebugMessage(QtFatalMsg, fmt);
00051 }
00052 
00053 /* Converts <b>str</b> to a ConnectionStatusReason enum value. */
00054 ConnectionStatusReason
00055 connectionStatusReasonFromString(const QString &str)
00056 {
00057   if (str.isEmpty())
00058     return UnrecognizedReason;
00059   if (!str.compare("MISC", Qt::CaseInsensitive))
00060     return MiscellaneousReason;
00061   if (!str.compare("IDENTITY", Qt::CaseInsensitive))
00062     return IdentityMismatch;
00063   if (!str.compare("RESOURCELIMIT", Qt::CaseInsensitive))
00064     return ResourceLimitReached;
00065   if (!str.compare("DONE", Qt::CaseInsensitive))
00066     return ConnectionDone;
00067   if (!str.compare("CONNECTREFUSED"))
00068     return ConnectionRefused;
00069   if (!str.compare("CONNECTRESET", Qt::CaseInsensitive))
00070     return ConnectionRefused;
00071   if (!str.compare("TIMEOUT", Qt::CaseInsensitive))
00072     return ConnectionTimeout;
00073   if (!str.compare("NOROUTE", Qt::CaseInsensitive))
00074     return NoRouteToHost;
00075   if (!str.compare("IOERROR", Qt::CaseInsensitive))
00076     return ConnectionIoError;
00077   return UnrecognizedReason;
00078 }
00079 
00080 /* Converts <b>str</b> to a Severity enum value. */
00081 Severity
00082 severityFromString(const QString &str)
00083 {
00084   if (!str.compare("DEBUG", Qt::CaseInsensitive))
00085     return DebugSeverity;
00086   if (!str.compare("INFO", Qt::CaseInsensitive))
00087     return InfoSeverity;
00088   if (!str.compare("NOTICE", Qt::CaseInsensitive))
00089     return NoticeSeverity;
00090   if (!str.compare("WARN", Qt::CaseInsensitive))
00091     return WarnSeverity;
00092   if (!str.compare("ERR", Qt::CaseInsensitive))
00093     return ErrorSeverity;
00094   return UnrecognizedSeverity;
00095 }
00096 
00097 }
00098