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 00043 #include "base/util/StringBuffer.h" 00044 #include "outlook/defs.h" 00045 00046 // Forward declarations 00047 class ClientFolder; 00048 class ClientItem; 00049 class ClientMail; 00050 class ClientContact; 00051 class ClientAppointment; 00052 class ClientTask; 00053 class ClientNote; 00054 00055 #include <string> 00056 00057 // documented MS structure that represent the timezone info 00058 // in the TZI registry 00059 typedef struct _REG_TZI_FORMAT 00060 { 00061 LONG Bias; 00062 LONG StandardBias; 00063 LONG DaylightBias; 00064 SYSTEMTIME StandardDate; 00065 SYSTEMTIME DaylightDate; 00066 } REG_TZI_FORMAT; 00067 00068 // 00069 // custom structure derived from REG_TZI_FORMAT. It is created 00070 // looking inside the MAPI property of the outlook timezone. 00071 // 00072 // 00073 typedef struct _REG_TZI_FORMAT_FOR_OUTLOOK 00074 { 00075 LONG Bias; 00076 LONG StandardBias; 00077 LONG DaylightBias; 00078 char TWO_BYTE_SEP1[2]; 00079 SYSTEMTIME StandardDate; 00080 char TWO_BYTE_SEP2[2]; 00081 SYSTEMTIME DaylightDate; 00082 } REG_TZI_FORMAT_FOR_OUTLOOK; 00083 00084 00095 class ClientApplication { 00096 00097 private: 00098 00100 static ClientApplication* pinstance; 00101 00103 std::wstring version; 00105 std::wstring programName; 00106 00107 00108 // Pointers to microsoft outlook objects. 00109 _ApplicationPtr pApp; 00110 _NameSpacePtr pMAPI; 00111 MAPIFolderPtr pFolder; 00112 00113 // Pointer to Redemption safe objects. 00114 Redemption::IMAPIUtilsPtr pRedUtils; 00115 Redemption::IRDOSessionPtr rdoSession; 00116 00117 00118 // Internal ClientObjects: 00119 // 'get..()' methods always return references to these objects 00120 ClientFolder* folder; 00121 ClientMail* mail; 00122 ClientContact* contact; 00123 ClientAppointment* appointment; 00124 ClientTask* task; 00125 ClientNote* note; 00126 00127 00129 HRESULT hr; 00130 00131 void createSafeInstances(); 00132 00133 // It decides how if we want to use the timezone in rec apps 00134 // for outgoing appointment. Set by the client in afterPrepareSync method 00135 bool useOutgoingTimezone; 00136 00145 TIME_ZONE_INFORMATION* convertRegTziOutlookFormat2TimezoneInformation(REG_TZI_FORMAT_FOR_OUTLOOK& rtf); 00146 00147 00157 REG_TZI_FORMAT convertTimezoneInformation2RegTziFormat(const TIME_ZONE_INFORMATION& rtf); 00158 00168 REG_TZI_FORMAT_FOR_OUTLOOK convertTimezoneInformation2RegTziOutlookFormat(const TIME_ZONE_INFORMATION& rtf); 00169 00179 bool getDisplayTimezone(REG_TZI_FORMAT& tz, Funambol::StringBuffer* display); 00180 00181 protected: 00182 00183 // Constructor 00184 ClientApplication(bool checkAttach = false); 00185 00186 00187 public: 00188 00189 // Method to get the sole instance of ClientApplication 00190 static ClientApplication* getInstance(bool checkAttach = false); 00191 00192 // Returns true if static instance is not NULL. 00193 static bool isInstantiated(); 00194 00195 // Destructor 00196 ~ClientApplication(); 00197 00198 00199 const std::wstring& getVersion(); 00200 const std::wstring& getName(); 00201 00202 00203 ClientFolder* getDefaultFolder (const std::wstring& itemType); 00204 ClientFolder* getFolderFromID (const std::wstring& folderID); 00205 ClientFolder* pickFolder (); 00206 ClientFolder* pickFolder (const std::wstring& itemType); 00207 ClientFolder* getFolderFromPath (const std::wstring& itemType, const std::wstring& path); 00208 ClientFolder* getDefaultRootFolder (); 00209 ClientFolder* getRootFolder (const int index); 00210 ClientFolder* getRootFolderFromName(const std::wstring& folderName); 00211 00212 ClientItem* getItemFromID (const std::wstring& itemID, const std::wstring& itemType); 00213 00214 00215 // Utility to release shared objects of Outlook session. 00216 HRESULT cleanUp(); 00217 00218 // Utility to convert an Exchange mail address into a SMTP address. 00219 std::wstring getSMTPfromEX(const std::wstring& EXAddress); 00220 00221 // Utility to get body of a specified item (used for notes body which is protected). 00222 std::wstring getBodyFromID(const std::wstring& itemID); 00223 00224 // Utility to retrieve the userName of current profile used. 00225 std::wstring getCurrentProfileName(); 00226 00227 // Returns true if Outlook MAPI object is logged on. 00228 const bool isLoggedOn(); 00229 00239 Funambol::StringBuffer getHexTimezone(const char *buf, int len); 00240 00246 void setTimezone(ClientAppointment* cApp); 00247 00255 TIME_ZONE_INFORMATION* getTimezone(ClientAppointment* cApp); 00256 00257 void setOutgoingTimezone(bool v) { useOutgoingTimezone = v; } 00258 bool getOutgoingTimezone() { return useOutgoingTimezone; } 00259 00272 bool setStartAndEnd(ClientAppointment* cApp, DATE start, DATE end); 00273 00281 bool isTheSameTimezoneRule(REG_TZI_FORMAT& tz, std::wstring* standardName); 00282 00289 bool isTheSameTimezoneRule(const TIME_ZONE_INFORMATION& tzInfo); 00290 00291 }; 00292 00295 #endif 00296