00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __ADDIN_H_
00039 #define __ADDIN_H_
00040
00041 #include "resource.h"
00042 #include "customization.h"
00043
00044
00045 #define PLUGIN_UI_CLASSNAME "FunambolApp" // The UI windows classname
00046 #define FUN "FUN"
00047 #define PARAM_OUTLOOK_SYNC "sync" // The command-line parameter passed to PROGRAM_NAME_EXE application
00048
00049 #define PARAM_OUTLOOK_OPTIONS "options" // It's used to open automatically the options dialog.
00050
00051
00052 #define BUTTON_SYNCHRONIZE L"&Sync All Ctrl+F7"
00053 #define BUTTON_GOTO_PLUGIN L"&Go to... Ctrl+F8"
00054 #define BUTTON_CONFIGURATION L"Op&tions... Ctrl+F9"
00055 #define TOOLTIP L"Sync All"
00056
00057
00058
00059
00060
00061
00062
00063
00064 #define PROPERTY_STATE "State" // The state of addin
00065 #define PROPERTY_PATH "installDir" // The path of application
00066 #define PROPERTY_NUM_INSTANCES "numInstances" // #instances of Addin for different users
00067 #define PROPERTY_SW_VERSION "swv" // Software version
00068 #define PROPERTY_MENUBAR_LABEL "menuLabel" // The menubar label, saved when the addin is created (to safely remove during uninstall)
00069 #define PROPERTY_COMMANDBAR_NAME "commandBarName" // The commandbar name, saved when the addin is created (to safely remove during uninstall)
00070
00071
00072
00073
00074
00075 #define ADDIN_CONTEXT "Microsoft/Office/Outlook/Addins/FunambolAddin.Addin"
00076
00077
00078 #define ADDIN_STATE_OK "ok"
00079 #define ADDIN_STATE_INSTALLING "installing"
00080 #define ADDIN_STATE_IN_PROGRESS "in progress"
00081 #define ADDIN_STATE_FAILED "failed"
00082 #define ADDIN_STATE_UNINSTALLED "uninstalled"
00083
00084
00085 #define LOG_FILENAME "FunambolAddin.log"
00086 #define LOG_DEFAULT_PATH "C:" // Normally not used, see openlog()
00087 #define TEMP_ENV "TEMP"
00088 #define MAX_ADDIN_LOG_SIZE 1000000 // 1 MB
00089
00090
00091
00092
00093
00094 #define ADDIN_MENU_LABEL_FUNAMBOL L"Funa&mbol"
00095
00096
00097 #define ADDIN_COMMAND_BAR_NAME PROGRAM_NAME
00098
00099
00100
00101 #define ADDIN_COMMAND_BAR_NAME_FUNAMBOL "Funambol Outlook Sync Client"
00102
00103
00104
00105 #define ADDIN_COMMAND_BAR_NAME_OLD "Funambol Outlook Plug-in"
00106
00107
00108 #define ERR_OPEN_EXPLORER "Error opening Outlook UI."
00109 #define ERR_COM_POINTER "COM Pointer Error. Code = %08lx: %ls"
00110 #define ERR_OPEN_APPLICATION "Error opening Outlook application."
00111 #define ERR_GET_COMMANDBARS "Error getting CommandBars."
00112 #define ERR_UNREG_DLL "Could not unregister Addin DLL."
00113 #define ERR_ADD_NEW_MENUBAR "Error adding a new MenuBar."
00114 #define ERR_ADD_NEW_COMMANDBAR "Error adding a new CommandBar."
00115 #define ERR_GET_COMMANDBAR "Error getting CommandBar."
00116 #define ERR_GET_MENUBAR "Error getting MenuBar."
00117 #define ERR_ADD_BUTTON1 "Error adding first Button."
00118 #define ERR_ADD_BUTTON2 "Error adding second Button."
00119 #define ERR_ADD_BUTTON3 "Error adding third Button."
00120 #define ERR_LINK_ICON "Error linking Commandbar icon Button."
00121 #define ERR_LINK_BUTTON1 "Error inking Menubar first Button."
00122 #define ERR_LINK_BUTTON2 "Error inking Menubar second Button."
00123 #define ERR_LINK_BUTTON3 "Error inking Menubar third Button."
00124 #define ERR_UNLINK_ICON "Error un-linking Commandbar icon Button."
00125 #define ERR_UNLINK_BUTTON1 "Error un-inking Menubar first Button."
00126 #define ERR_UNLINK_BUTTON2 "Error un-inking Menubar second Button."
00127 #define ERR_UNLINK_BUTTON3 "Error un-inking Menubar third Button."
00128 #define ERR_REMOVING_ADDIN "Error occurred removing Addin from Outlook."
00129 #define ERR_INSTALL_DIR_KEY "Could not retrieve path of %s under reg key %s/%s."
00130
00131 #define ERR_CODE_BAD_POINTER 0x80004003
00132
00133
00134
00135
00136
00137 extern _ATL_FUNC_INFO OnClickButtonInfo;
00138 extern _ATL_FUNC_INFO OnClickSynchronizationInfo;
00139 extern _ATL_FUNC_INFO OnClickGotoInfo;
00140 extern _ATL_FUNC_INFO OnClickConfigurationInfo;
00141
00142 static void toWindows(char* str);
00143
00144
00145
00146
00147
00148 class ATL_NO_VTABLE Caddin : public CComObjectRootEx<CComSingleThreadModel>,
00149 public CComCoClass<Caddin, &CLSID_addin>,
00150 public ISupportErrorInfo,
00151 public IDispatchImpl<Iaddin, &IID_Iaddin, &LIBID_FUNAMBOLADDINLib>,
00152 public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
00153 public IDispEventSimpleImpl<1,Caddin,&__uuidof(_CommandBarButtonEvents)>,
00154 public IDispEventSimpleImpl<2,Caddin,&__uuidof(_CommandBarButtonEvents)>,
00155 public IDispEventSimpleImpl<3,Caddin,&__uuidof(_CommandBarButtonEvents)>,
00156 public IDispEventSimpleImpl<4,Caddin,&__uuidof(_CommandBarButtonEvents)>
00157 {
00158
00159 public:
00160
00161 typedef IDispEventSimpleImpl< 1,Caddin, &__uuidof(_CommandBarButtonEvents)> ButtonSyncEvent;
00162 typedef IDispEventSimpleImpl< 2,Caddin, &__uuidof(_CommandBarButtonEvents)> ItemSynchronizationEvent;
00163 typedef IDispEventSimpleImpl< 3,Caddin, &__uuidof(_CommandBarButtonEvents)> ItemGotoEvent;
00164 typedef IDispEventSimpleImpl< 4,Caddin, &__uuidof(_CommandBarButtonEvents)> ItemConfigurationEvent;
00165
00166 Caddin(){}
00167 virtual ~Caddin() {}
00168
00169 DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
00170 DECLARE_PROTECT_FINAL_CONSTRUCT()
00171
00172 BEGIN_COM_MAP(Caddin)
00173 COM_INTERFACE_ENTRY(Iaddin)
00174
00175 COM_INTERFACE_ENTRY(ISupportErrorInfo)
00176 COM_INTERFACE_ENTRY2(IDispatch, Iaddin)
00177 COM_INTERFACE_ENTRY(_IDTExtensibility2)
00178 END_COM_MAP()
00179
00180 BEGIN_SINK_MAP(Caddin)
00181 SINK_ENTRY_INFO(1, __uuidof(_CommandBarButtonEvents), 0x01, OnClickButton, &OnClickButtonInfo)
00182 SINK_ENTRY_INFO(2, __uuidof(_CommandBarButtonEvents), 0x01, OnClickSynchronization, &OnClickSynchronizationInfo)
00183 SINK_ENTRY_INFO(3, __uuidof(_CommandBarButtonEvents), 0x01, OnClickGoto, &OnClickGotoInfo)
00184 SINK_ENTRY_INFO(4, __uuidof(_CommandBarButtonEvents), 0x01, OnClickConfiguration, &OnClickConfigurationInfo)
00185 END_SINK_MAP()
00186
00187
00188 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
00189
00190
00191 void __stdcall OnClickButton (IDispatch* Ctrl,VARIANT_BOOL * CancelDefault);
00192 void __stdcall OnClickSynchronization(IDispatch* Ctrl,VARIANT_BOOL * CancelDefault);
00193 void __stdcall OnClickGoto (IDispatch* Ctrl,VARIANT_BOOL * CancelDefault);
00194 void __stdcall OnClickConfiguration (IDispatch* Ctrl,VARIANT_BOOL * CancelDefault);
00195
00196
00197 public:
00198
00199
00200 STDMETHOD(OnConnection) (IDispatch* Application, ext_ConnectMode ConnectMode, IDispatch* AddInInst, SAFEARRAY** custom);
00201 STDMETHOD(OnDisconnection) (ext_DisconnectMode RemoveMode, SAFEARRAY** custom);
00202 STDMETHOD(OnStartupComplete)(SAFEARRAY** custom);
00203 STDMETHOD(OnBeginShutdown) (SAFEARRAY** custom);
00204 STDMETHOD(OnAddInsUpdate) (SAFEARRAY** custom){ return E_NOTIMPL; }
00205
00206 HRESULT AddNewMenubar (_CommandBars *pCmdBars);
00207 HRESULT AddNewCommandBar(_CommandBars *pCmdBars);
00208
00209 HRESULT __stdcall Caddin::DispAdviseControls (void);
00210 HRESULT __stdcall Caddin::DispUnadviseControls(void);
00211
00212 void launchSyncClientOutlook (const char* parameter);
00213 char* readPropertyValueFromHKLM(const char* context, const char* prop);
00214 int setCurrentSwv();
00215 char* readAddinSwv();
00216 bool swvNotCompatible(const char* currentVersion, const char* oldVersion);
00217
00222 char* readPropertyValue(const char* propertyName);
00223
00228 void setPropertyValue(const char* propertyName, const char* propertyValue);
00229
00230 bool removeCommandBar(_CommandBarsPtr commandBars, const char* commandBarName);
00231 bool removeMenuBar(CommandBarControlsPtr commandBar, const WCHAR* menuBarName);
00232
00233 HRESULT removeAddin();
00234 bool isAddinInstalled();
00235
00236 int saveAddinState(char* state);
00237 bool checkErrorsLastTime();
00238 void errorMsgBox();
00239 void openLog();
00240 void manageComErrors(_com_error &e);
00241
00242 bool isLastInstance();
00243 void updateAddinInstances(bool increment);
00244
00245
00246 private:
00247 LPDISPATCH m_pParentApp;
00248 _ApplicationPtr applicationPtr;
00249
00250 };
00251
00252 #endif //__ADDIN_H_