Back to index

lightning-sunbird  0.9+nobinonly
MozABConduitGenCond.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * EXPORTED FUNCTIONS Conduit Entry Points Source File
00004  *
00005  **************************************************************************/
00006 #define STRICT 1
00007 #define ASSERT(f)          ((void)0)
00008 #define TRACE0(sz)
00009 #define TRACE(sz)
00010 
00011 #include <malloc.h>
00012 
00013 
00014 #include <CPalmRec.cpp>
00015 #include <CPString.cpp>
00016 #include <CPCatgry.cpp>
00017 
00018 #include <windows.h>
00019 #include <string.h>
00020 #include <stdio.h>
00021 #ifdef METROWERKS_WIN
00022 #include <wmem.h>
00023 #else
00024 #include <memory.h>
00025 #endif
00026 #include <sys/stat.h>
00027 #include <TCHAR.H>
00028 #include <COMMCTRL.H>
00029 
00030 #include <syncmgr.h>
00031 #include "MozABConduitGenCond.h"
00032 #include "resource.h"
00033 
00034 #include <logstrng.h>
00035 
00036 // TODO - Include custom sync header
00037 
00038 #include <PALM_CMN.H>
00039 #define CONDUIT_NAME "MozABConduit"
00040 #include "MozABConduitSync.h"
00041 
00042 HANDLE hLangInstance;
00043 HANDLE hAppInstance;
00044 extern HANDLE hLangInstance;
00045 extern HANDLE hAppInstance;
00046 
00047 long CALLBACK CondCfgDlgProc(HWND hWnd, UINT Message, WPARAM wParam, 
00048                              LPARAM lParam);
00049 void LdCfgDlgBmps(HWND hDlg);
00050 
00052 //
00054 //
00055 //     Function:        DllMain()
00056 //
00057 //     Description:    main entry point to the MozABConduitProto component
00058 //
00059 //     Parameters:    hInstance - instance handle of the DLL
00060 //                    dwReason  - why the entry point was called
00061 //                    lpReserved - reserved
00062 //
00063 //     Returns:        1 if okay
00064 //
00066 #ifndef _68K_
00067 
00068 static int iTerminationCount = 0;
00069 
00070 DWORD tId = 0;
00071 
00072 
00073 extern "C" int APIENTRY
00074 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
00075 {
00076 
00077 
00078     if (dwReason == DLL_PROCESS_ATTACH)
00079     {
00080         TRACE0("EXPORTED FUNCTIONS Initializing!\n");
00081         
00082         if (!iTerminationCount ) {
00083             hAppInstance = hInstance;
00084             // use PalmLoadLanguage here to load different languages
00085             hLangInstance = hInstance;
00086         }
00087         ++iTerminationCount;
00088 
00089         tId = TlsAlloc();
00090         if (tId == 0xFFFFFFFF)
00091             return FALSE;
00092     }
00093     else if (dwReason == DLL_PROCESS_DETACH)
00094     {
00095         TRACE0("EXPORTED FUNCTIONS Terminating!\n");
00096 
00097         --iTerminationCount;
00098         if (!iTerminationCount ) {
00099             // use PalmFreeLanguage here to unload different languages
00100         }
00101         TlsFree(tId);
00102     }
00103     return 1;   // ok
00104 }
00105 #endif
00106 
00107 
00109 //
00111 //
00112 //     Function:        OpenConduit()
00113 //
00114 //     Description:  Extern "C" entry point into this conduit which starts 
00115 //                   the process of synchronizing the local database table 
00116 //                   with a remote conterpart residing on the remote view 
00117 //                   device. 
00118 //
00119 //     Parameters:   Pointer to a callback function used to report progress.
00120 //                    
00121 //                
00122 //
00123 //     Returns:        
00124 //
00126 ExportFunc long OpenConduit(PROGRESSFN pFn, CSyncProperties& rProps)
00127 {
00128     long retval = -1;
00129     if (pFn)
00130     {
00131        CMozABConduitSync * pABSync = new CMozABConduitSync(rProps);
00132         if (pABSync)
00133               {
00134             retval = pABSync->Perform();
00135             delete pABSync;
00136         }
00137     }
00138     return(retval);
00139 }
00140 
00142 //
00144 //
00145 //       Function:              GetConduitName()
00146 //
00147 //       Description:  Extern "C" entry point into this conduit which returns
00148 //                                the name to be used when display messages 
00149 //                                regarding this conduit.
00150 //
00151 //       Parameters:   pszName - buffer in which to place the name
00152 //                                 nLen - maximum number of bytes of buffer     
00153 //                                      
00154 //                              
00155 //
00156 //       Returns:          -1 indicates erros
00157 //
00159 ExportFunc long GetConduitName(char* pszName,WORD nLen)
00160 {
00161     strncpy(pszName,CONDUIT_NAME, nLen-1);   
00162     *(pszName+nLen-1) = '\0';
00163 
00164     return 0;
00165 }
00166 
00168 //
00170 //
00171 //       Function:     GetConduitVersion()
00172 //
00173 //       Description:  Extern "C" entry point into this conduit which returns
00174 //                     the conduits version
00175 //
00176 //       Parameters:   none
00177 //
00178 //       Returns:      DWORD indicating major and minor version number
00179 //                        HIWORD - reserved
00180 //                        HIBYTE(LOWORD) - major number
00181 //                        LOBYTE(LOWORD) - minor number
00182 //
00184 ExportFunc DWORD GetConduitVersion()
00185 {
00186     return GENERIC_CONDUIT_VERSION;
00187 }
00188 
00190 //
00192 //
00193 //       Function:     ConfigureConduit
00194 //
00195 //       Description:  Extern "C" entry point into this conduit which returns
00196 //                     should display the UI necessary to configure this 
00197 //                     conduit.
00198 //
00199 //       Parameters:   none
00200 //
00201 //       Returns:      0 - success, !0 - failure
00202 //
00204 ExportFunc long ConfigureConduit(CSyncPreference& pref)
00205 {
00206 
00207     long nRtn = -1;
00208     CfgConduitInfoType cfgcond;
00209     cfgcond.dwVersion = CFGCONDUITINFO_VERSION_1;
00210     cfgcond.dwSize  = sizeof(CfgConduitInfoType);
00211     cfgcond.dwCreatorId = 0;
00212     cfgcond.dwUserId = 0;
00213     memset(cfgcond.szUser , 0, sizeof(cfgcond.szUser));
00214     memset(cfgcond.m_PathName, 0, sizeof(cfgcond.m_PathName)); 
00215     cfgcond.syncPermanent = pref.m_SyncType;
00216     cfgcond.syncTemporary = pref.m_SyncType;
00217     cfgcond.syncNew = pref.m_SyncType;
00218     cfgcond.syncPref = eTemporaryPreference; 
00219 
00220     int irv;
00221     irv = DialogBoxParam((HINSTANCE)hLangInstance, 
00222               MAKEINTRESOURCE(IDD_CONDUIT_ACTION), 
00223               GetForegroundWindow(), 
00224               (DLGPROC)CondCfgDlgProc,
00225               (LPARAM)&cfgcond);
00226     if (irv == 0) 
00227        {
00228         pref.m_SyncType = cfgcond.syncNew;
00229         pref.m_SyncPref = cfgcond.syncPref;
00230         nRtn = 0;
00231     }
00232 
00233     return nRtn;
00234 }
00235 
00237 // 
00239 //
00240 //   Method:        GetConduitInfo
00241 //
00242 //   Description:   This function provides a way for a Conduit to provide 
00243 //                  info to the caller.  In this version of the call, MFC 
00244 //                  Version, Conduit Name, and Default sync action are the 
00245 //                  types of information this call will return.
00246 //
00247 //   Parameters:    ConduitInfoEnum infoType - enum specifying what info is 
00248 //                                             being requested.
00249 //
00250 //                  void *pInArgs - This parameter may be null, except for 
00251 //                                  the Conduit name enum, this value will 
00252 //                                  be a ConduitRequestInfoType structure.
00253 //
00254 //                  This following two parameters vary depending upon the 
00255 //                  info being requested. 
00256 //
00257 //                  For enum eConduitName
00258 //                  void *pOut - will be a pointer to a character buffer
00259 //                  DWORD *pdwOutSize - will be a pointer to a DWORD 
00260 //                                      specifying the size of the 
00261 //                                      character buffer.
00262 //
00263 //                  For enum eMfcVersion
00264 //                  void *pOut - will be a pointer to a DWORD
00265 //                  DWORD *pdwOutSize - will be a pointer to a DWORD 
00266 //                                      specifying the size of pOut.
00267 //
00268 //                  For enum eDefaultAction
00269 //                  void *pOut - will be a pointer to a eSyncType variable
00270 //                  DWORD *pdwOutSize - will be a pointer to a DWORD 
00271 //                                      specifying the size of pOut.
00272 //
00273 //   Returns:       0   - Success.
00274 //                  !0  - error code.
00275 //
00277 ExportFunc long GetConduitInfo(ConduitInfoEnum infoType, void *pInArgs, 
00278                                void *pOut, DWORD *pdwOutSize)
00279 {
00280     if (!pOut)
00281         return CONDERR_INVALID_PTR;
00282     if (!pdwOutSize)
00283         return CONDERR_INVALID_OUTSIZE_PTR;
00284 
00285     switch (infoType) 
00286        {
00287         case eConduitName:
00288 
00289             // This code is for example. This conduit does not use this code
00290             
00291             if (!pInArgs)
00292                 return CONDERR_INVALID_INARGS_PTR;
00293             ConduitRequestInfoType *pInfo;
00294             pInfo = (ConduitRequestInfoType *)pInArgs;
00295             if ((pInfo->dwVersion != CONDUITREQUESTINFO_VERSION_1) ||
00296                 (pInfo->dwSize != SZ_CONDUITREQUESTINFO))
00297                 return CONDERR_INVALID_INARGS_STRUCT;
00298            
00299                 pOut = CONDUIT_NAME;
00300                 return CONDERR_CONDUIT_RESOURCE_FAILURE;
00301             break;
00302         case eDefaultAction:
00303             if (*pdwOutSize != sizeof(eSyncTypes))
00304                 return CONDERR_INVALID_BUFFER_SIZE;
00305             (*(eSyncTypes*)pOut) = eFast;
00306             break;
00307         case eMfcVersion:
00308             if (*pdwOutSize != sizeof(DWORD))
00309                 return CONDERR_INVALID_BUFFER_SIZE;
00310             (*(DWORD*)pOut) = MFC_NOT_USED;
00311             break;
00312         default:
00313             return CONDERR_UNSUPPORTED_CONDUITINFO_ENUM;
00314     }
00315     return 0;
00316 }
00317 
00318 long CALLBACK CondCfgDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
00319 {
00320     static CfgConduitInfoType *pCfgInfo;
00321     TCHAR szPath[256];
00322 
00323     switch (Message) 
00324        {
00325       case WM_INITDIALOG:
00326 
00327         if (lParam != 0) {
00328           TCHAR szBuffer[256];
00329           TCHAR szBuf2[256];
00330           LoadString((HINSTANCE)hLangInstance, IDS_SYNC_ACTION_TEXT, szBuffer, 
00331                      sizeof(szBuffer));
00332           SetDlgItemText(hWnd, IDC_ACTIONGROUPBOXTEXT, szBuffer);
00333 
00334           LoadString((HINSTANCE)hLangInstance, IDS_CONDUIT_NAME, szBuffer, 
00335                      sizeof(szBuffer));
00336           SetWindowText(hWnd, szBuffer);
00337      
00338           // Load the bitmaps properly
00339           LdCfgDlgBmps(hWnd);
00340 
00341           pCfgInfo = (CfgConduitInfoType *)lParam;
00342           switch (pCfgInfo->syncTemporary)
00343                 {
00344             case eFast:
00345             case eSlow:
00346               CheckRadioButton(hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, 
00347                                IDC_RADIO_SYNC);
00348               LoadString((HINSTANCE)hLangInstance, IDS_SYNC_FILES, szBuffer, 
00349                          sizeof(szBuffer));
00350               break;
00351             case ePCtoHH:
00352               CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, IDC_RADIO_PCTOHH);
00353               LoadString((HINSTANCE)hLangInstance, IDS_PCTOHH, szBuffer, sizeof(szBuffer));
00354               break;
00355             case eHHtoPC:
00356               CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, IDC_RADIO_HHTOPC);
00357               LoadString((HINSTANCE)hLangInstance, IDS_HHTOPC, szBuffer, sizeof(szBuffer));
00358               break;
00359             case eDoNothing:
00360             default:
00361               CheckRadioButton(hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, 
00362                                IDC_RADIO_DONOTHING);
00363               LoadString((HINSTANCE)hLangInstance, IDS_DO_NOTHING, szBuffer,
00364                          sizeof(szBuffer));
00365               break;
00366           }
00367           // did we get called from the old config call or the new cfg call?
00368           if (pCfgInfo->dwCreatorId != 0) 
00369                 {
00370             SetDlgItemText(hWnd, IDC_STATIC_TEMPORARY, szBuffer);
00371 
00372             switch (pCfgInfo->syncPermanent)
00373                      {
00374               case eFast:
00375               case eSlow:
00376                 LoadString((HINSTANCE)hLangInstance, IDS_SYNC_FILES, szBuffer,
00377                            sizeof(szBuffer));
00378                 break;
00379               case ePCtoHH:
00380                 LoadString((HINSTANCE)hLangInstance, IDS_PCTOHH, szBuffer,
00381                            sizeof(szBuffer));
00382                 break;
00383 
00384               case eHHtoPC:
00385                 LoadString((HINSTANCE)hLangInstance, IDS_HHTOPC, szBuffer,
00386                            sizeof(szBuffer));
00387                 break;
00388               case eDoNothing:
00389               default:
00390                 LoadString((HINSTANCE)hLangInstance, IDS_DO_NOTHING, szBuffer,
00391                            sizeof(szBuffer));
00392                 break;
00393             }
00394             SetDlgItemText(hWnd, IDC_STATIC_PERMANENT, szBuffer);
00395 
00396             LoadString((HINSTANCE)hLangInstance, IDS_CURRENT_SETTINGS_GROUP, 
00397                        szBuffer, sizeof(szBuffer));
00398             wsprintf(szBuf2, szBuffer, pCfgInfo->szUser);
00399             SetDlgItemText(hWnd, IDC_CURRENT_SETTINGS_GROUP, szBuf2);
00400           }
00401         }
00402         break;
00403       case WM_COMMAND:
00404         switch (wParam) 
00405               {
00406           case IDC_RADIO_SYNC:
00407           case IDC_RADIO_DONOTHING:
00408           case IDC_RADIO_HHTOPC:
00409           case IDC_RADIO_PCTOHH:
00410             CheckRadioButton( hWnd, IDC_RADIO_SYNC, IDC_RADIO_DONOTHING, wParam);
00411             break;
00412           case IDCANCEL:
00413             EndDialog(hWnd, 1);
00414             return TRUE;
00415           case IDOK:
00416             if (IsDlgButtonChecked(hWnd, IDC_RADIO_SYNC)) 
00417                 pCfgInfo->syncNew = eFast;
00418             else if (IsDlgButtonChecked(hWnd, IDC_RADIO_PCTOHH)) 
00419                 pCfgInfo->syncNew = ePCtoHH;
00420             else if (IsDlgButtonChecked(hWnd, IDC_RADIO_HHTOPC))
00421                 pCfgInfo->syncNew = eHHtoPC;
00422             else
00423                 pCfgInfo->syncNew = eDoNothing;
00424             pCfgInfo->syncPref = (IsDlgButtonChecked(hWnd, IDC_MAKEDEFAULT))
00425                             ?  ePermanentPreference : eTemporaryPreference;
00426             EndDialog(hWnd, 0);
00427             return TRUE;
00428           default:
00429             break;
00430         }
00431         break;
00432 
00433       case WM_SYSCOLORCHANGE:
00434         LdCfgDlgBmps(hWnd);
00435         break;
00436 
00437       default:
00438         break;
00439     }
00440     return FALSE;
00441 }
00442 
00443 void LdCfgDlgBmps(HWND hDlg)
00444 {
00445   COLORMAP    cMap;
00446   HWND        hwndButton;
00447   HBITMAP     hBmp, hOldBmp;
00448 
00449   //
00450   // setup the bitmaps
00451   //
00452   cMap.to = GetSysColor(COLOR_BTNFACE);
00453   cMap.from = RGB(192,192,192);
00454 
00455   // Sync 
00456   hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_SYNC, 0, &cMap, 1);
00457   // associate the bitmap with the button.
00458   if ((hwndButton = GetDlgItem(hDlg, IDC_SYNC)) != NULL)
00459   {
00460     hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
00461                                    (WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
00462     if (hOldBmp != NULL)
00463       DeleteObject((HGDIOBJ)hOldBmp);
00464   }
00465 
00466   // Do Nothing 
00467   hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_DONOTHING, 0, &cMap, 1);
00468   // associate the bitmap with the button.
00469   if ((hwndButton = GetDlgItem(hDlg, IDC_DONOTHING)) != NULL)
00470   {
00471     hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
00472                                    (WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
00473     if (hOldBmp != NULL)
00474       DeleteObject((HGDIOBJ)hOldBmp);
00475   }
00476   hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_PCTOHH, 0, &cMap, 1);
00477   // associate the bitmap with the button.
00478   if ((hwndButton = GetDlgItem(hDlg, IDC_PCTOHH)) != NULL)
00479   {
00480     hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
00481                                    (WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
00482     if (hOldBmp != NULL)
00483       DeleteObject((HGDIOBJ)hOldBmp);
00484   }
00485   hBmp = CreateMappedBitmap((HINSTANCE)hLangInstance, IDB_HHTOPC, 0, &cMap, 1);
00486   // associate the bitmap with the button.
00487   if ((hwndButton = GetDlgItem(hDlg, IDC_HHTOPC)) != NULL)
00488   {
00489     hOldBmp = (HBITMAP)SendMessage(hwndButton, STM_SETIMAGE,
00490                                    (WPARAM)IMAGE_BITMAP, (LPARAM)(HANDLE)hBmp);
00491     if (hOldBmp != NULL)
00492       DeleteObject((HGDIOBJ)hOldBmp);
00493   }
00494 }