javaextensions/globalindicators/src/CGlobalIndicators.cpp
changeset 78 71ad690e91f5
parent 72 1f0034e370aa
child 80 d6dafc5d983f
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Controls the native global indicators.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32property.h> // Publish & Subscribe
       
    22 #include <coreapplicationuisdomainpskeys.h>
       
    23 #include "CGlobalIndicators.h"
       
    24 #include "com_nokia_mid_ui_GlobalIndicators.h"
       
    25 #include "logger.h"
       
    26 
       
    27 //  CONSTANTS
       
    28 namespace
       
    29 {
       
    30 // These constants are from JNI header, just defined shorter names here
       
    31 // If any other values are used for the indicator or its value, they are
       
    32 // passed directly to P&S.
       
    33 const TInt KPropertyGlobalMailIndicator =
       
    34     com_nokia_mid_ui_GlobalIndicators_MAIL_INDICATOR;
       
    35 
       
    36 const TInt KPropertyGlobalChatIndicator =
       
    37     com_nokia_mid_ui_GlobalIndicators_CHAT_INDICATOR;
       
    38 
       
    39 const TInt KPropertyGlobalIndicatorUninitialized =
       
    40     com_nokia_mid_ui_GlobalIndicators_INDICATOR_UNINITIALIZED;
       
    41 
       
    42 const TInt KPropertyGlobalIndicatorHide =
       
    43     com_nokia_mid_ui_GlobalIndicators_INDICATOR_HIDE;
       
    44 
       
    45 const TInt KPropertyGlobalIndicatorShow =
       
    46     com_nokia_mid_ui_GlobalIndicators_INDICATOR_SHOW;
       
    47 }
       
    48 
       
    49 // Required capabilites
       
    50 // WriteDeviceData  // for setting the email status using RProperty::Set()
       
    51 // ReadDeviceData   // for retrieving the email status using RProperty::Get()
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // SetGlobalIndicator
       
    57 // Sets the value for given global indicator.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TInt CGlobalIndicators::SetGlobalIndicator(TInt aIndicator, TInt aValue)
       
    61 {
       
    62 
       
    63     LOG2(EJavaGlobalInd, EInfo,
       
    64          "GlobalIndicators::SetGlobalIndicator indicator:%d, value:%d",
       
    65          aIndicator, aValue);
       
    66 
       
    67 
       
    68     // Make sure that indicator JNI constants match into P&S definitions used
       
    69     // in platform.
       
    70     TUint32 convertedIndicator = aIndicator;
       
    71     if (aIndicator == KPropertyGlobalMailIndicator)
       
    72     {
       
    73         convertedIndicator = KCoreAppUIsNewEmailStatus;
       
    74     }
       
    75     if (aIndicator == KPropertyGlobalChatIndicator)
       
    76     {
       
    77         convertedIndicator = KCoreAppUIsUipInd;
       
    78     }
       
    79 
       
    80     TInt readValue = KPropertyGlobalIndicatorUninitialized;
       
    81     RProperty property;
       
    82 
       
    83     TInt ret = property.Attach(KPSUidCoreApplicationUIs, convertedIndicator);
       
    84     if (KErrNone == ret)
       
    85     {
       
    86         ret = property.Get(readValue);
       
    87         TInt setValue = KPropertyGlobalIndicatorUninitialized;
       
    88 
       
    89         // For Email and Chat indicators, use the specific known P&S values
       
    90         if (convertedIndicator == KCoreAppUIsNewEmailStatus ||
       
    91                 convertedIndicator == KCoreAppUIsUipInd)
       
    92         {
       
    93             if (aValue == KPropertyGlobalIndicatorShow)
       
    94             {
       
    95                 // Always ok to turn on - just check if is was already on
       
    96                 if (readValue != ECoreAppUIsNewEmail &&
       
    97                         readValue != ECoreAppUIsShow)
       
    98                 {
       
    99                     if (convertedIndicator == KCoreAppUIsNewEmailStatus)
       
   100                     {
       
   101                         setValue = ECoreAppUIsNewEmail;
       
   102                     }
       
   103                     if (convertedIndicator == KCoreAppUIsUipInd)
       
   104                     {
       
   105                         setValue = ECoreAppUIsShow;
       
   106                     }
       
   107 
       
   108                     ret = property.Set(setValue);
       
   109                     readValue = KPropertyGlobalIndicatorShow;
       
   110                     LOG1(EJavaGlobalInd, EInfo,
       
   111                          "GlobalIndicators::SetGlobalIndicator ON, value:%D",
       
   112                          setValue);
       
   113                 }
       
   114             }
       
   115             else if (aValue == KPropertyGlobalIndicatorHide)
       
   116             {
       
   117                 // When turning email inficator off bear in mind that there is
       
   118                 // no way to know for sure if some other application still would
       
   119                 // like to have the indicator turned on.
       
   120                 if (readValue != ECoreAppUIsNoNewEmail &&
       
   121                         readValue != ECoreAppUIsDoNotShow)
       
   122                 {
       
   123                     if (convertedIndicator == KCoreAppUIsNewEmailStatus)
       
   124                     {
       
   125                         setValue = ECoreAppUIsNoNewEmail;
       
   126                     }
       
   127                     if (convertedIndicator == KCoreAppUIsUipInd)
       
   128                     {
       
   129                         setValue = ECoreAppUIsDoNotShow;
       
   130                     }
       
   131 
       
   132                     ret = property.Set(setValue);
       
   133                     readValue = KPropertyGlobalIndicatorHide;
       
   134                     LOG1(EJavaGlobalInd, EInfo,
       
   135                          "GlobalIndicators::SetGlobalIndicator OFF, value:%D",
       
   136                          setValue);
       
   137                 }
       
   138             }
       
   139             else
       
   140             {
       
   141                 // Value is not HIDE or SHOW. Try to set it anyway.
       
   142                 ret = property.Set(aValue);
       
   143                 readValue = aValue;
       
   144                 LOG1(EJavaGlobalInd, EInfo,
       
   145                      "GlobalIndicators::SetGlobalIndicator value:%D",
       
   146                      aValue);
       
   147             }
       
   148         }
       
   149 
       
   150         else // other than Email or Chat indicator
       
   151         {
       
   152             ret = property.Set(aValue);
       
   153             readValue = aValue;
       
   154             LOG1(EJavaGlobalInd, EInfo,
       
   155                  "GlobalIndicators::SetGlobalIndicator [user defined] value:%D",
       
   156                  aValue);
       
   157         }
       
   158 
       
   159     }
       
   160     property.Close();
       
   161     if (KErrNone != ret)
       
   162     {
       
   163         LOG1(EJavaGlobalInd, EInfo,
       
   164              "GlobalIndicators::SetGlobalIndicator property error :%D",
       
   165              ret);
       
   166         readValue = ret;
       
   167     }
       
   168 
       
   169     // return the property value or an error code
       
   170     return readValue;
       
   171 }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // GlobalIndicator
       
   175 // Gets the value of given global indicator.
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 TInt CGlobalIndicators::GlobalIndicator(TInt aIndicator)
       
   179 {
       
   180     LOG(EJavaGlobalInd, EInfo, "GlobalIndicators::GlobalIndicator");
       
   181     RProperty property;
       
   182     TInt readValue = 0;
       
   183     TInt ret = KErrNotFound;
       
   184 
       
   185     if (aIndicator == KPropertyGlobalMailIndicator)
       
   186     {
       
   187         ret = property.Attach(
       
   188                   KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus);
       
   189     }
       
   190     else if (aIndicator == KPropertyGlobalChatIndicator)
       
   191     {
       
   192         ret = property.Attach(
       
   193                   KPSUidCoreApplicationUIs, KCoreAppUIsUipInd);
       
   194     }
       
   195     else
       
   196     {
       
   197         // A specific indicator (other than mail or chat indicator)
       
   198         ret = property.Attach(
       
   199                   KPSUidCoreApplicationUIs, aIndicator);
       
   200     }
       
   201 
       
   202     // If Attach has succeeded, try reading the Property value
       
   203     if (KErrNone == ret)
       
   204     {
       
   205         ret = property.Get(readValue);
       
   206         property.Close();
       
   207     }
       
   208 
       
   209     // If also reading has succeeded, return the Property value
       
   210     if (KErrNone == ret)
       
   211     {
       
   212         return readValue ;
       
   213     }
       
   214     else
       
   215     {
       
   216         return ret;
       
   217     }
       
   218 }
       
   219 
       
   220 //  End of File