Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Events | Private Member Functions | Private Attributes
nsMessengerOSXIntegration Class Reference

#include <nsMessengerOSXIntegration.h>

Inheritance diagram for nsMessengerOSXIntegration:
Inheritance graph
[legend]
Collaboration diagram for nsMessengerOSXIntegration:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMessengerOSXIntegration ()
virtual ~nsMessengerOSXIntegration ()
virtual nsresult Init ()
void OnItemAdded (in nsIRDFResource parentItem, in nsISupports item)
void OnItemRemoved (in nsIRDFResource parentItem, in nsISupports item)
void OnItemPropertyChanged (in nsIRDFResource item, in nsIAtom property, in string oldValue, in string newValue)
void OnItemIntPropertyChanged (in nsIRDFResource item, in nsIAtom property, in long oldValue, in long newValue)
void OnItemBoolPropertyChanged (in nsIRDFResource item, in nsIAtom property, in boolean oldValue, in boolean newValue)
void OnItemUnicharPropertyChanged (in nsIRDFResource item, in nsIAtom property, in wstring oldValue, in wstring newValue)
void OnItemPropertyFlagChanged (in nsIMsgDBHdr item, in nsIAtom property, in unsigned long oldFlag, in unsigned long newFlag)
void OnItemEvent (in nsIMsgFolder item, in nsIAtom event)

Public Attributes

const folderListenerNotifyFlagValue added = 0x1
const folderListenerNotifyFlagValue removed = 0x2
const folderListenerNotifyFlagValue propertyChanged = 0x4
const folderListenerNotifyFlagValue intPropertyChanged = 0x8
const folderListenerNotifyFlagValue boolPropertyChanged = 0x10
const folderListenerNotifyFlagValue unicharPropertyChanged = 0x20
const folderListenerNotifyFlagValue propertyFlagChanged = 0x40

Events

const
folderListenerNotifyFlagValue=0 
x80
const folderListenerNotifyFlagValue all = 0xFFFFFFFF

Private Member Functions

PRInt32 CountNewMessages ()
nsresult OnAlertFinished (const PRUnichar *aAlertCookie)

Private Attributes

nsCOMPtr< nsISupportsArraymFoldersWithNewMail
nsCOMPtr< nsIAtommBiffStateAtom
PRPackedBool mBiffIconVisible
PRPackedBool mSuppressBiffIcon
PRPackedBool mAlertInProgress

Detailed Description

Definition at line 56 of file nsMessengerOSXIntegration.h.


Constructor & Destructor Documentation

Definition at line 84 of file nsMessengerOSXIntegration.cpp.

{
  if (mBiffIconVisible) 
  {
    RestoreApplicationDockTileImage();
    mBiffIconVisible = PR_FALSE;
  }
}

Member Function Documentation

Definition at line 144 of file nsMessengerOSXIntegration.cpp.

{
  // iterate over all the folders in mFoldersWithNewMail
  nsCOMPtr<nsIMsgFolder> folder;
  nsCOMPtr<nsIWeakReference> weakReference;
  PRInt32 numNewMessages = 0;
  PRInt32 totalNewMessages = 0;
  
  PRUint32 count = 0;
  mFoldersWithNewMail->Count(&count);

  for (PRUint32 index = 0; index < count; index++)
  {
    weakReference = do_QueryElementAt(mFoldersWithNewMail, index);
    folder = do_QueryReferent(weakReference);
    if (folder)
    {

      numNewMessages = 0;   
      folder->GetNumNewMessages(PR_TRUE, &numNewMessages);
      totalNewMessages += numNewMessages;
    } // if we got a folder
  } // for each folder

  return totalNewMessages;
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 104 of file nsMessengerOSXIntegration.cpp.

{
  nsresult rv;
    
  nsCOMPtr <nsIMsgAccountManager> accountManager = 
    do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  // because we care if the default server changes
  rv = accountManager->AddRootFolderListener(this);
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  // because we care if the unread total count changes
  rv = mailSession->AddFolderListener(this, nsIFolderListener::boolPropertyChanged | nsIFolderListener::intPropertyChanged);
  NS_ENSURE_SUCCESS(rv,rv);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 172 of file nsMessengerOSXIntegration.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr<nsIPrefBranch> prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  
  PRBool bounceDockIcon = PR_FALSE; 
  prefBranch->GetBoolPref("mail.biff.animate_dock_icon", &bounceDockIcon);

  // This will call GetAttention(), which will bounce the dock icon.
  if (!mSuppressBiffIcon)
  {
    nsCOMPtr<nsIWindowMediator> mediator (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
    if (bounceDockIcon && mediator)
    {
      nsCOMPtr<nsIDOMWindowInternal> domWindow;
      mediator->GetMostRecentWindow(NS_LITERAL_STRING("mail:3pane").get(), getter_AddRefs(domWindow));
      if (domWindow)
         {
        nsCOMPtr<nsIDOMChromeWindow> chromeWindow(do_QueryInterface(domWindow));
        chromeWindow->GetAttention();
         }
    }

    // This will change the dock icon.     
    // If we want to overlay the number of new messages on top of
    // the icon ...
    
    // use OverlayApplicationDockTileImage
    // -- you'll have to pass it a CGImage, and somehow we have to
    // create the CGImage with the numbers. tricky    
    PRInt32 totalNewMessages = CountNewMessages();
    CGContextRef context = ::BeginCGContextForApplicationDockTile();
    
    // Draw a circle.

    ::CGContextBeginPath(context);
    ::CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
    ::CGContextClosePath(context);

    // use #2fc600 for the color.
    ::CGContextSetRGBFillColor(context, 0.184, 0.776, 0.0, 1);

    //::CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.7);
    ::CGContextFillPath(context);

    // Draw the number.
    nsAutoString total;
    total.AppendInt(totalNewMessages);

    // Use a system font (kThemeUtilityWindowTitleFont)
    ScriptCode sysScript = ::GetScriptManagerVariable(smSysScript);

    Str255 fontName;
    SInt16 fontSize;
    Style fontStyle;
    ::GetThemeFont(kThemeSmallEmphasizedSystemFont, sysScript, fontName,
                   &fontSize, &fontStyle);

    FMFontFamily family = ::FMGetFontFamilyFromName(fontName);
    FMFont fmFont;
    OSStatus err = ::FMGetFontFromFontFamilyInstance(family, fontStyle, &fmFont,
                                                     nsnull);
    if (err != noErr) 
       {
         NS_WARNING("FMGetFontFromFontFamilyInstance failed");
         ::EndCGContextForApplicationDockTile(context);
         return NS_ERROR_FAILURE;
    }

    ATSUStyle style;
    err = ::ATSUCreateStyle(&style);
    if (err != noErr) 
       {
      NS_WARNING("ATSUCreateStyle failed");
         ::EndCGContextForApplicationDockTile(context);
      return NS_ERROR_FAILURE;
       }
        
    Fixed size = Long2Fix(24);
    RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF };
    
    ATSUAttributeTag tags[3] = { kATSUFontTag, kATSUSizeTag, kATSUColorTag };
    ByteCount valueSizes[3] = { sizeof(ATSUFontID), sizeof(Fixed),
                                sizeof(RGBColor) };
    ATSUAttributeValuePtr values[3] = { &fmFont, &size, &white };

    err = ::ATSUSetAttributes(style, 3, tags, valueSizes, values);
    if (err != noErr) {
        NS_WARNING("ATSUSetAttributes failed");
        ::ATSUDisposeStyle(style);
        ::EndCGContextForApplicationDockTile(context);

        return NS_ERROR_FAILURE;
      }

    UniCharCount runLengths = kATSUToTextEnd;
    ATSUTextLayout textLayout;
    err = ::ATSUCreateTextLayoutWithTextPtr(total.get(),
                                            kATSUFromTextBeginning,
                                            kATSUToTextEnd, total.Length(), 1,
                                            &runLengths, &style, &textLayout);
    if (err != noErr) 
       {
        NS_WARNING("ATSUCreateTextLayoutWithTextPtr failed");
        ::ATSUDisposeStyle(style);
        ::EndCGContextForApplicationDockTile(context);

        return NS_ERROR_FAILURE;
    }

    ATSUAttributeTag layoutTags[1] = { kATSUCGContextTag };
    ByteCount layoutValueSizes[1] = { sizeof(CGContextRef) };
    ATSUAttributeValuePtr layoutValues[1] = { &context };

    err = ::ATSUSetLayoutControls(textLayout, 1, layoutTags, layoutValueSizes,
                                  layoutValues);
    if (err != noErr) 
       {
        NS_WARNING("ATSUSetLayoutControls failed");
        ::ATSUDisposeStyle(style);
        ::EndCGContextForApplicationDockTile(context);
        return NS_ERROR_FAILURE;
    }

    Rect boundingBox;
    err = ::ATSUMeasureTextImage(textLayout, kATSUFromTextBeginning,
                                 kATSUToTextEnd, Long2Fix(0), Long2Fix(0),
                                 &boundingBox);
    if (err != noErr) 
       {
        NS_WARNING("ATSUMeasureTextImage failed");
        ::ATSUDisposeStyle(style);
        ::EndCGContextForApplicationDockTile(context);
        return NS_ERROR_FAILURE;
    }

    // Center text inside circle
    err = ::ATSUDrawText(textLayout, kATSUFromTextBeginning, kATSUToTextEnd,
                         Long2Fix(90 - (boundingBox.right - boundingBox.left) / 2),
                         Long2Fix(95 - (boundingBox.bottom - boundingBox.top) / 2));

    ::ATSUDisposeStyle(style);
    ::ATSUDisposeTextLayout(textLayout);

    ::CGContextFlush(context);

    ::EndCGContextForApplicationDockTile(context);
    mBiffIconVisible = PR_TRUE;
  }

  mSuppressBiffIcon = PR_FALSE;
  mAlertInProgress = PR_FALSE;
  return NS_OK;
}

Here is the call graph for this function:

void nsIFolderListener::OnItemAdded ( in nsIRDFResource  parentItem,
in nsISupports  item 
) [inherited]

Here is the caller graph for this function:

void nsIFolderListener::OnItemBoolPropertyChanged ( in nsIRDFResource  item,
in nsIAtom  property,
in boolean  oldValue,
in boolean  newValue 
) [inherited]

Here is the caller graph for this function:

void nsIFolderListener::OnItemEvent ( in nsIMsgFolder  item,
in nsIAtom  event 
) [inherited]

Here is the caller graph for this function:

void nsIFolderListener::OnItemIntPropertyChanged ( in nsIRDFResource  item,
in nsIAtom  property,
in long  oldValue,
in long  newValue 
) [inherited]

Here is the caller graph for this function:

void nsIFolderListener::OnItemPropertyChanged ( in nsIRDFResource  item,
in nsIAtom  property,
in string  oldValue,
in string  newValue 
) [inherited]
void nsIFolderListener::OnItemPropertyFlagChanged ( in nsIMsgDBHdr  item,
in nsIAtom  property,
in unsigned long  oldFlag,
in unsigned long  newFlag 
) [inherited]

Here is the caller graph for this function:

void nsIFolderListener::OnItemRemoved ( in nsIRDFResource  parentItem,
in nsISupports  item 
) [inherited]
void nsIFolderListener::OnItemUnicharPropertyChanged ( in nsIRDFResource  item,
in nsIAtom  property,
in wstring  oldValue,
in wstring  newValue 
) [inherited]

Member Data Documentation

Definition at line 49 of file nsIFolderListener.idl.

Definition at line 69 of file nsIFolderListener.idl.

Definition at line 63 of file nsIFolderListener.idl.

Definition at line 76 of file nsMessengerOSXIntegration.h.

Definition at line 74 of file nsMessengerOSXIntegration.h.

Definition at line 70 of file nsMessengerOSXIntegration.h.

Definition at line 69 of file nsMessengerOSXIntegration.h.

Definition at line 75 of file nsMessengerOSXIntegration.h.

Definition at line 57 of file nsIFolderListener.idl.

Definition at line 81 of file nsIFolderListener.idl.

Definition at line 53 of file nsIFolderListener.idl.

Definition at line 75 of file nsIFolderListener.idl.


Event Documentation

Definition at line 90 of file nsIFolderListener.idl.

Definition at line 87 of file nsIFolderListener.idl.


The documentation for this class was generated from the following files: