logsui/logsengine/logssymbianos/src/logsforegroundwatcher.cpp
changeset 20 6a40edd41841
equal deleted inserted replaced
19:e4c884866116 20:6a40edd41841
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "logsforegroundwatcher.h"
       
    19 #include "logslogger.h"
       
    20 #include <apacmdln.h>
       
    21 
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // Currently no other way to monitor first app foreground switch in case
       
    25 // mainwindow is not made yet visible.
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 LogsForegroundWatcher::LogsForegroundWatcher(QObject* parent) : QObject(parent)
       
    29 {
       
    30     CCoeEnv* env = CCoeEnv::Static();
       
    31     if (env) {
       
    32         TRAP_IGNORE(env->AddForegroundObserverL(*this));
       
    33     }
       
    34 }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 LogsForegroundWatcher::~LogsForegroundWatcher()
       
    41 {
       
    42     CCoeEnv* env = CCoeEnv::Static();
       
    43     if (env) {
       
    44         env->RemoveForegroundObserver(*this);
       
    45     }
       
    46 }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void LogsForegroundWatcher::ensureBackgroundStartup()
       
    53 {
       
    54     CApaCommandLine* commandLine = 0;
       
    55     CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine);
       
    56     if ( commandLine ){
       
    57         TApaCommand command = commandLine->Command();
       
    58         if (command != EApaCommandBackground) {
       
    59             LOGS_QDEBUG( "logs [UI] -> LogsForegroundWatcher::ensureBackgroundStartup");
       
    60             TRAPD( err, commandLine->SetCommandL( EApaCommandBackground ) );
       
    61             if ( !err ){
       
    62                 RProcess thisProcess;
       
    63                 TRAP_IGNORE( commandLine->SetProcessEnvironmentL(thisProcess) )
       
    64             }
       
    65             LOGS_QDEBUG( "logs [UI] <- LogsForegroundWatcher::ensureBackgroundStartup");
       
    66         }
       
    67         delete commandLine;
       
    68     }
       
    69 }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void LogsForegroundWatcher::HandleGainingForeground()
       
    76 {
       
    77     LOGS_QDEBUG( "logs [UI] -> LogsForegroundWatcher::HandleGainingForeground" );
       
    78     emit gainingForeground();
       
    79     LOGS_QDEBUG( "logs [UI] <- LogsForegroundWatcher::HandleGainingForeground" );
       
    80 }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void LogsForegroundWatcher::HandleLosingForeground()
       
    87 {
       
    88     LOGS_QDEBUG( "logs [UI] -> LogsForegroundWatcher::HandleLosingForeground" );
       
    89     emit losingForeground();
       
    90     LOGS_QDEBUG( "logs [UI] <- LogsForegroundWatcher::HandleLosingForeground" );
       
    91 }
       
    92