home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / prefs / CReceiptsMediator.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.6 KB  |  129 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CReceiptsMediator.h"
  20.  
  21. #include "macutil.h"
  22.  
  23. #include "prefapi.h"
  24.  
  25. #include <LGACaption.h>
  26. #include <UModalDialogs.h>
  27.  
  28. //-----------------------------------
  29. CReceiptsMediator::CReceiptsMediator(LStream*)
  30. //-----------------------------------
  31. :    CPrefsMediator(class_ID)
  32. ,    mCustomDialogHandler(nil)
  33. {
  34. } // CReceiptsMediator::CReceiptsMediator
  35.  
  36. //-----------------------------------
  37. CReceiptsMediator::~CReceiptsMediator()
  38. //-----------------------------------
  39. {
  40.     FinalizeCustomDialog();
  41. } // CReceiptsMediator::~CReceiptsMediator
  42.  
  43. //-----------------------------------
  44. void CReceiptsMediator::WritePrefs()
  45. //-----------------------------------
  46. {
  47.     FinalizeCustomDialog();
  48. } // CReceiptsMediator::WritePrefs
  49.  
  50. //-----------------------------------
  51. void CReceiptsMediator::FinalizeCustomDialog()
  52. //-----------------------------------
  53. {
  54.     delete mCustomDialogHandler; // this causes controls to write themselves.
  55.     mCustomDialogHandler = nil;
  56. } // CReceiptsMediator::FinalizeCustomDialog
  57.  
  58. //-----------------------------------
  59. void CReceiptsMediator::DoCustomDialog()
  60. //-----------------------------------
  61. {
  62.     LWindow* dialog = nil;
  63.     try
  64.     {
  65.         Boolean firstTime = (mCustomDialogHandler == nil);
  66.         if (firstTime)
  67.             mCustomDialogHandler = new StDialogHandler(12010, nil);
  68.         dialog = mCustomDialogHandler->GetDialog();
  69.         
  70.  
  71.         if (firstTime)
  72.         {
  73.             // Set up the domain name in the caption.
  74.             char buf[256];
  75.             const char* domainName = buf;
  76.             int bufLength = sizeof(buf);
  77.             PREF_GetCharPref("mail.identity.defaultdomain", buf, &bufLength);
  78.             if (!domainName[0])
  79.             {
  80.                 bufLength = sizeof(buf);
  81.                 PREF_GetCharPref("mail.identity.useremail", buf, &bufLength);
  82.                 char* cp = strchr(buf, '@');
  83.                 if (cp)
  84.                     domainName = cp + 1;
  85.             }
  86.             LGACaption* domainField = (LGACaption*)dialog->FindPaneByID('Domn');
  87.             ThrowIfNil_(domainField);
  88.             CStr255 captionText;
  89.             
  90.             domainField->GetDescriptor(captionText);
  91.             StringParamText(captionText, domainName);
  92.             domainField->SetDescriptor(captionText);
  93.         }
  94.         dialog->Show();
  95.         dialog->Select();
  96.  
  97.         MessageT message = msg_Nothing;
  98.         do {
  99.             message = mCustomDialogHandler->DoDialog();
  100.         } while (message != msg_OK && message != msg_Cancel); // actually, there's no cancel.
  101.         
  102.         // Use the result.
  103.         if (message == msg_OK)
  104.         {
  105.             // Nothing to do, the prefs are written out when the dialog is destroyed.
  106.         }
  107.     }
  108.     catch(...)
  109.     {
  110.     }
  111.     if (dialog)
  112.         dialog->Hide(); // don't delete, we delete when we want to write the prefs.
  113. } // CReceiptsMediator::DoCustomDialog
  114.  
  115. //-----------------------------------
  116. void CReceiptsMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  117. //-----------------------------------
  118. {
  119.     switch (inMessage)
  120.     {
  121.         case 'Cust':
  122.             DoCustomDialog();
  123.             break;
  124.         default:
  125.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  126.             break;
  127.     }
  128. } // CReceiptsMediator::ListenToMessage
  129.