Vidalia 0.2.10
|
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.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file tcglobal.cpp 00013 ** \version $Id: tcglobal.cpp 4054 2009-08-17 02:25:08Z edmanm $ 00014 ** \brief Provides common methods and constants used by the torcontrol library 00015 */ 00016 00017 #include "tcglobal.h" 00018 00019 00020 namespace tc { 00021 00022 /* Creates a new message using <b>fmt</b> and a severity level of 00023 * QtDebugMsg. */ 00024 DebugMessage 00025 debug(const QString &fmt) 00026 { 00027 return DebugMessage(QtDebugMsg, fmt); 00028 } 00029 00030 /* Creates a new message using <b>fmt</b> and a severity level of 00031 * QtWarningMsg. */ 00032 DebugMessage 00033 warn(const QString &fmt) 00034 { 00035 return DebugMessage(QtWarningMsg, fmt); 00036 } 00037 00038 /* Creates a new message using <b>fmt</b> and a severity level of 00039 * QtCriticalMsg. */ 00040 DebugMessage 00041 error(const QString &fmt) 00042 { 00043 return DebugMessage(QtCriticalMsg, fmt); 00044 } 00045 00046 /* Creates a new message using <b>fmt</b> and a severity level of 00047 * QtFatalMsg. */ 00048 DebugMessage 00049 fatal(const QString &fmt) 00050 { 00051 return DebugMessage(QtFatalMsg, fmt); 00052 } 00053 00054 /* Converts <b>str</b> to a ConnectionStatusReason enum value. */ 00055 ConnectionStatusReason 00056 connectionStatusReasonFromString(const QString &str) 00057 { 00058 if (str.isEmpty()) 00059 return UnrecognizedReason; 00060 if (!str.compare("MISC", Qt::CaseInsensitive)) 00061 return MiscellaneousReason; 00062 if (!str.compare("IDENTITY", Qt::CaseInsensitive)) 00063 return IdentityMismatch; 00064 if (!str.compare("RESOURCELIMIT", Qt::CaseInsensitive)) 00065 return ResourceLimitReached; 00066 if (!str.compare("DONE", Qt::CaseInsensitive)) 00067 return ConnectionDone; 00068 if (!str.compare("CONNECTREFUSED")) 00069 return ConnectionRefused; 00070 if (!str.compare("CONNECTRESET", Qt::CaseInsensitive)) 00071 return ConnectionRefused; 00072 if (!str.compare("TIMEOUT", Qt::CaseInsensitive)) 00073 return ConnectionTimeout; 00074 if (!str.compare("NOROUTE", Qt::CaseInsensitive)) 00075 return NoRouteToHost; 00076 if (!str.compare("IOERROR", Qt::CaseInsensitive)) 00077 return ConnectionIoError; 00078 return UnrecognizedReason; 00079 } 00080 00081 /* Converts <b>str</b> to a Severity enum value. */ 00082 Severity 00083 severityFromString(const QString &str) 00084 { 00085 if (!str.compare("DEBUG", Qt::CaseInsensitive)) 00086 return DebugSeverity; 00087 if (!str.compare("INFO", Qt::CaseInsensitive)) 00088 return InfoSeverity; 00089 if (!str.compare("NOTICE", Qt::CaseInsensitive)) 00090 return NoticeSeverity; 00091 if (!str.compare("WARN", Qt::CaseInsensitive)) 00092 return WarnSeverity; 00093 if (!str.compare("ERR", Qt::CaseInsensitive)) 00094 return ErrorSeverity; 00095 return UnrecognizedSeverity; 00096 } 00097 00098 } 00099