Back to index

lightning-sunbird  0.9+nobinonly
calUtils.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Sun Microsystems code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Sun Microsystems, Inc.
00018  * Portions created by the Initial Developer are Copyright (C) 2007
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Daniel Boelzle <daniel.boelzle@sun.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #if !defined(INCLUDED_CAL_UTILS_H)
00038 #define INCLUDED_CAL_UTILS_H
00039 
00040 #if defined(MOZILLA_INTERNAL_API)
00041 #include "nsCRT.h"
00042 #include "nsString.h"
00043 #else
00044 #include "nsMemory.h"
00045 #include "nsCRTGlue.h"
00046 #include "nsStringAPI.h"
00047 #endif
00048 
00049 #include "nsAutoPtr.h"
00050 #include "nsVoidArray.h"
00051 #include "nsIStringEnumerator.h"
00052 
00053 #include "calITimezone.h"
00054 #include "calITimezoneProvider.h"
00055 #include "calIICSService.h"
00056 #include "nsIConsoleService.h"
00057 #include "nsCOMPtr.h"
00058 
00059 #define CAL_STRLEN_ARGS(x) x, sizeof(x)-1
00060 #define CAL_ENSURE_MEMORY(p) NS_ENSURE_TRUE(p, NS_ERROR_OUT_OF_MEMORY)
00061 
00062 typedef struct _icaltimezone icaltimezone;
00063 typedef struct icaltimetype icaltimetype;
00064 
00065 namespace cal {
00066 
00074 nsresult createUTF8StringEnumerator(nsAutoPtr<nsCStringArray> & takeOverArray,
00075                                     nsIUTF8StringEnumerator ** ppRet);
00076 
00080 nsresult logError(PRUnichar const* msg);
00081 inline nsresult logError(char const* msg) {
00082     return logError(NS_ConvertASCIItoUTF16(msg).get());
00083 }
00084 inline nsresult logError(nsACString const& msg) {
00085     return logError(NS_ConvertASCIItoUTF16(msg).get());
00086 }
00087 
00091 nsresult logWarning(PRUnichar const* msg);
00092 inline nsresult logWarning(char const* msg) {
00093     return logWarning(NS_ConvertASCIItoUTF16(msg).get());
00094 }
00095 inline nsresult logWarning(nsACString const& msg) {
00096     return logWarning(NS_ConvertASCIItoUTF16(msg).get());
00097 }
00098 
00102 nsresult log(PRUnichar const* msg);
00103 inline nsresult log(char const* msg) {
00104     return log(NS_ConvertASCIItoUTF16(msg).get());
00105 }
00106 inline nsresult log(nsACString const& msg) {
00107     return log(NS_ConvertASCIItoUTF16(msg).get());
00108 }
00109 
00110 // some static timezone helpers, we leak those, but this is ok since the
00111 // underlying service leaks those anyway until process termination
00112 
00116 nsCOMPtr<nsIConsoleService> const& getConsoleService();
00117 
00121 nsCOMPtr<calIICSService> const& getICSService();
00122 
00126 nsCOMPtr<calITimezoneService> const& getTimezoneService();
00127 
00131 nsCOMPtr<calITimezone> const& floating();
00132 
00136 nsCOMPtr<calITimezone> const& UTC();
00137 
00146 icaltimezone * getIcalTimezone(calITimezone * tz);
00147 
00156 nsCOMPtr<calITimezone> detectTimezone(icaltimetype const& icalt,
00157                                       calITimezoneProvider * tzProvider);
00158 
00162 void logMissingTimezone(char const* tzid);
00163 
00169 class XpcomBase {
00170 protected:
00171     XpcomBase() {}
00172     virtual ~XpcomBase();
00173 private:
00174     XpcomBase(XpcomBase const&); // left unimplemented
00175     XpcomBase const& operator=(XpcomBase const&); // left unimplemented
00176 };
00177 
00178 } // namespace cal
00179 
00180 #endif // !defined(INCLUDED_CAL_UTILS_H)