00001 /* 00002 * Funambol is a mobile platform developed by Funambol, Inc. 00003 * Copyright (C) 2003 - 2007 Funambol, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Affero General Public License version 3 as published by 00007 * the Free Software Foundation with the addition of the following permission 00008 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 00009 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 00010 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU Affero General Public License 00018 * along with this program; if not, see http://www.gnu.org/licenses or write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00020 * MA 02110-1301 USA. 00021 * 00022 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 00023 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com. 00024 * 00025 * The interactive user interfaces in modified source and object code versions 00026 * of this program must display Appropriate Legal Notices, as required under 00027 * Section 5 of the GNU Affero General Public License version 3. 00028 * 00029 * In accordance with Section 7(b) of the GNU Affero General Public License 00030 * version 3, these Appropriate Legal Notices must retain the display of the 00031 * "Powered by Funambol" logo. If the display of the logo is not reasonably 00032 * feasible for technical reasons, the Appropriate Legal Notices must display 00033 * the words "Powered by Funambol". 00034 */ 00035 00036 #ifndef INCL_CLIENTAPPLICATION 00037 #define INCL_CLIENTAPPLICATION 00038 00044 #include "outlook/defs.h" 00045 #include "outlook/ClientFolder.h" 00046 #include "outlook/ClientItem.h" 00047 #include "outlook/ClientMail.h" 00048 #include "outlook/ClientContact.h" 00049 #include "outlook/ClientAppointment.h" 00050 #include "outlook/ClientTask.h" 00051 #include "outlook/ClientNote.h" 00052 00053 #include <string> 00054 00055 // documented MS structure that represent the timezone info 00056 // in the TZI registry 00057 typedef struct _REG_TZI_FORMAT 00058 { 00059 LONG Bias; 00060 LONG StandardBias; 00061 LONG DaylightBias; 00062 SYSTEMTIME StandardDate; 00063 SYSTEMTIME DaylightDate; 00064 } REG_TZI_FORMAT; 00065 00066 // 00067 // custom structure derived from REG_TZI_FORMAT. It is created 00068 // looking inside the MAPI property of the outlook timezone. 00069 // 00070 // 00071 typedef struct _REG_TZI_FORMAT_FOR_OUTLOOK 00072 { 00073 LONG Bias; 00074 LONG StandardBias; 00075 LONG DaylightBias; 00076 char TWO_BYTE_SEP1[2]; 00077 SYSTEMTIME StandardDate; 00078 char TWO_BYTE_SEP2[2]; 00079 SYSTEMTIME DaylightDate; 00080 } REG_TZI_FORMAT_FOR_OUTLOOK; 00081 00082 00093 class ClientApplication { 00094 00095 private: 00096 00098 static ClientApplication* pinstance; 00099 00101 std::wstring version; 00103 std::wstring programName; 00104 00105 00106 // Pointers to microsoft outlook objects. 00107 _ApplicationPtr pApp; 00108 _NameSpacePtr pMAPI; 00109 MAPIFolderPtr pFolder; 00110 00111 // Pointer to Redemption safe objects. 00112 Redemption::IMAPIUtilsPtr pRedUtils; 00113 Redemption::IRDOSessionPtr rdoSession; 00114 00115 00116 // Internal ClientObjects: 00117 // 'get..()' methods always return references to these objects 00118 ClientFolder* folder; 00119 ClientMail* mail; 00120 ClientContact* contact; 00121 ClientAppointment* appointment; 00122 ClientTask* task; 00123 ClientNote* note; 00124 00125 00127 HRESULT hr; 00128 00129 void createSafeInstances(); 00130 00131 // It decides how if we want to use the timezone in rec apps 00132 // for outgoing appointment. Set by the client in afterPrepareSync method 00133 bool useOutgoingTimezone; 00134 00143 TIME_ZONE_INFORMATION* convertRegTziOutlookFormat2TimezoneInformation(REG_TZI_FORMAT_FOR_OUTLOOK& rtf); 00144 00145 00155 REG_TZI_FORMAT convertTimezoneInformation2RegTziFormat(const TIME_ZONE_INFORMATION& rtf); 00156 00166 REG_TZI_FORMAT_FOR_OUTLOOK convertTimezoneInformation2RegTziOutlookFormat(const TIME_ZONE_INFORMATION& rtf); 00167 00177 bool getDisplayTimezone(REG_TZI_FORMAT& tz, StringBuffer* display); 00178 00179 protected: 00180 00181 // Constructor 00182 ClientApplication(); 00183 00184 00185 public: 00186 00187 // Method to get the sole instance of ClientApplication 00188 static ClientApplication* getInstance(); 00189 00190 // Returns true if static instance is not NULL. 00191 static bool isInstantiated(); 00192 00193 // Destructor 00194 ~ClientApplication(); 00195 00196 00197 const std::wstring& getVersion(); 00198 const std::wstring& getName(); 00199 00200 00201 ClientFolder* getDefaultFolder (const std::wstring& itemType); 00202 ClientFolder* getFolderFromID (const std::wstring& folderID); 00203 ClientFolder* pickFolder (); 00204 ClientFolder* pickFolder (const std::wstring& itemType); 00205 ClientFolder* getFolderFromPath (const std::wstring& itemType, const std::wstring& path); 00206 ClientFolder* getDefaultRootFolder (); 00207 ClientFolder* getRootFolder (const int index); 00208 ClientFolder* getRootFolderFromName(const std::wstring& folderName); 00209 00210 ClientItem* getItemFromID (const std::wstring& itemID, const std::wstring& itemType); 00211 00212 00213 // Utility to release shared objects of Outlook session. 00214 HRESULT cleanUp(); 00215 00216 // Utility to convert an Exchange mail address into a SMTP address. 00217 std::wstring getSMTPfromEX(const std::wstring& EXAddress); 00218 00219 // Utility to get body of a specified item (used for notes body which is protected). 00220 std::wstring getBodyFromID(const std::wstring& itemID); 00221 00222 // Utility to retrieve the userName of current profile used. 00223 std::wstring getCurrentProfileName(); 00224 00225 // Returns true if Outlook MAPI object is logged on. 00226 const bool isLoggedOn(); 00227 00237 StringBuffer getHexTimezone(const char *buf, int len); 00238 00244 void setTimezone(ClientAppointment* cApp); 00245 00253 TIME_ZONE_INFORMATION* getTimezone(ClientAppointment* cApp); 00254 00255 void setOutgoingTimezone(bool v) { useOutgoingTimezone = v; } 00256 bool getOutgoingTimezone() { return useOutgoingTimezone; } 00257 00270 bool setStartAndEnd(ClientAppointment* cApp, DATE start, DATE end); 00271 00279 bool isTheSameTimezoneRule(REG_TZI_FORMAT& tz, std::wstring* standardName); 00280 00287 bool isTheSameTimezoneRule(const TIME_ZONE_INFORMATION& tzInfo); 00288 00289 }; 00290 00293 #endif 00294