app/src/mpmtpinfolink.cpp
author hgs
Fri, 11 Jun 2010 19:36:32 -0500
changeset 37 eb79a7c355bf
child 43 0f32e550d9d8
child 48 af3740e3753f
permissions -rw-r--r--
201023

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: Music Player MTP info link. This class is used to provide a link
*              to educate the user about MTP after a successful manual refresh.
*              Basically this class inherits from HbLabel and catches mouse events,
*              when clicked it opens a url already specified in settings.
*
*/

//Qt
#include <QUrl>
#include <QDesktopServices>
#include <QGraphicsSceneMouseEvent>

//Orbit
#include <hbparameterlengthlimiter.h>

//Local
#include "mpsettingsmanager.h"
#include "mpmtpinfolink.h"
#include "mptrace.h"

/*!
    \class MpMtpInfoLink
    \brief MpMtpInfoLink provides a label that can handle mouse events.

    When label is clicked it opens a URL containing MTP information.
*/

/*!
 Constructs MpMtpInfoLink.
 */
MpMtpInfoLink::MpMtpInfoLink()
{
    TX_ENTRY
    setTextWrapping( Hb::TextWrapAnywhere );
    setMtpInfoText();
    TX_EXIT
}

/*!
 Destructs the MpMtpInfoLink.
 */
MpMtpInfoLink::~MpMtpInfoLink()
{
    TX_LOG
}

/*!
 Catches mouse press events.
 */
void MpMtpInfoLink::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
    Q_UNUSED( event );
}

/*!
 Catches mouse release event.
 */
void MpMtpInfoLink::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
{
    TX_ENTRY
    QRectF itemRect = boundingRect();
    QPointF releasePoint = event->lastPos();
    if ( itemRect.contains( releasePoint ) ) {
        QUrl url( MpSettingsManager::instance()->mtpInfoUrl() );
        QDesktopServices::openUrl( url );
    }
    TX_EXIT
}

/*!
 \internal
 Set text to be shown in html format
 */
void MpMtpInfoLink::setMtpInfoText()
{
    TX_ENTRY
    QString url = MpSettingsManager::instance()->mtpInfoUrl();
    QString text = HbParameterLengthLimiter( "txt_mus_info_please_note_that_using_media_transfer" ).arg( url );
    QString htmlLink = "<a href=\"" + url + "\">" + url + "</a>" ;
    text.replace( url, htmlLink );
    text = "<p>" + text + "</p>" ;
    setHtml( text );
    TX_EXIT
}