<commit_before>//
// This file is part of the Marble Project.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2006-2007 <NAME> <<EMAIL>>
// Copyright 2007      <NAME>  <<EMAIL>>
// Copyright 2008      <NAME>  <<EMAIL>>
//

// Self
#include "TinyWebBrowser.h"

// Qt
#include <QFileInfo>
#include <QPointer>
#include <QRegExp>
#include <QAction>
#include <QDesktopServices>
#include <QPainter>
#include <QPrintDialog>
#include <QPrinter>
#include <QTextFrame>

// Marble
#include "MarbleGlobal.h"
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include "MarbleLocale.h"

namespace Marble
{

class TinyWebBrowserPrivate
{
};

static QString guessWikipediaDomain()
{
    const QString code = MarbleLocale::languageCode();

    return QString ( "http://%1.m.wikipedia.org/" ).arg ( code );
}

TinyWebBrowser::TinyWebBrowser( QWidget* parent )
    : QWebView( parent ),
      d( 0 )
{
    connect( this, SIGNAL(statusBarMessage(QString)),
             this, SIGNAL(statusMessage(QString)) );

    page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
    connect( this, SIGNAL(linkClicked(QUrl)),
             this, SLOT(openExternalLink(QUrl)) );
    connect( this, SIGNAL(titleChanged(QString)),
             this, SLOT(setWindowTitle(QString)) );

    pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
    pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
}

TinyWebBrowser::~TinyWebBrowser()
{
    // not yet needed
    //delete d;
}

void TinyWebBrowser::setWikipediaPath( const QString& relativeUrl )
{
    QUrl url = relativeUrl;
    if ( url.isRelative() )
        url = QUrl( guessWikipediaDomain() ).resolved( url );
    load( url );
}

void TinyWebBrowser::print()
{
#ifndef QT_NO_PRINTER	
    QPrinter printer;

    QPointer<QPrintDialog> dlg = new QPrintDialog( &printer, this );
    if ( dlg->exec() )
        QWebView::print( &printer );
    delete dlg;
#endif
}

QWebView *TinyWebBrowser::createWindow( QWebPage::WebWindowType type )
{
    TinyWebBrowser *view = new TinyWebBrowser( this );

    if ( type == QWebPage::WebModalDialog ) {
        view->setWindowModality( Qt::WindowModal );
    }

    return view;
}

void TinyWebBrowser::openExternalLink( QUrl url )
{
    QDesktopServices::openUrl( url );
}

QByteArray TinyWebBrowser::userAgent(const QString &platform, const QString &component)
{
    QString result( "Mozilla/5.0 (compatible; Marble/%1; %2; %3)" );
    result = result.arg( MARBLE_VERSION_STRING, platform, component);
    return result.toLatin1();
}


} // namespace Marble

#include "TinyWebBrowser.moc"<commit_msg>Different user-agent strings for mobile and desktop devices<commit_after>//
// This file is part of the Marble Project.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2006-2007 <NAME> <<EMAIL>>
// Copyright 2007      <NAME>  <<EMAIL>>
// Copyright 2008      <NAME>  <<EMAIL>>
//

// Self
#include "TinyWebBrowser.h"

// Qt
#include <QFileInfo>
#include <QPointer>
#include <QRegExp>
#include <QAction>
#include <QDesktopServices>
#include <QPainter>
#include <QPrintDialog>
#include <QPrinter>
#include <QTextFrame>

// Marble
#include "MarbleGlobal.h"
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include "MarbleLocale.h"

namespace Marble
{

class TinyWebBrowserPrivate
{
};

static QString guessWikipediaDomain()
{
    const QString code = MarbleLocale::languageCode();

    return QString ( "http://%1.m.wikipedia.org/" ).arg ( code );
}

TinyWebBrowser::TinyWebBrowser( QWidget* parent )
    : QWebView( parent ),
      d( 0 )
{
    connect( this, SIGNAL(statusBarMessage(QString)),
             this, SIGNAL(statusMessage(QString)) );

    page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
    connect( this, SIGNAL(linkClicked(QUrl)),
             this, SLOT(openExternalLink(QUrl)) );
    connect( this, SIGNAL(titleChanged(QString)),
             this, SLOT(setWindowTitle(QString)) );

    pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
    pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
}

TinyWebBrowser::~TinyWebBrowser()
{
    // not yet needed
    //delete d;
}

void TinyWebBrowser::setWikipediaPath( const QString& relativeUrl )
{
    QUrl url = relativeUrl;
    if ( url.isRelative() )
        url = QUrl( guessWikipediaDomain() ).resolved( url );
    load( url );
}

void TinyWebBrowser::print()
{
#ifndef QT_NO_PRINTER	
    QPrinter printer;

    QPointer<QPrintDialog> dlg = new QPrintDialog( &printer, this );
    if ( dlg->exec() )
        QWebView::print( &printer );
    delete dlg;
#endif
}

QWebView *TinyWebBrowser::createWindow( QWebPage::WebWindowType type )
{
    TinyWebBrowser *view = new TinyWebBrowser( this );

    if ( type == QWebPage::WebModalDialog ) {
        view->setWindowModality( Qt::WindowModal );
    }

    return view;
}

void TinyWebBrowser::openExternalLink( QUrl url )
{
    QDesktopServices::openUrl( url );
}

QByteArray TinyWebBrowser::userAgent(const QString &platform, const QString &component)
{
    QString result( "Mozilla/5.0 (compatible; Marble/%1; %2; %3; %4)" );
    bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
    QString const device = smallScreen ? "MobileDevice" : "DesktopDevice";
    result = result.arg( MARBLE_VERSION_STRING, device, platform, component);
    return result.toLatin1();
}


} // namespace Marble

#include "TinyWebBrowser.moc"
{'fraction_non_alphanumeric': 0.13303964757709252, 'fraction_numerical': 0.008634361233480176, 'mean_word_length': 3.893103448275862, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648990', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1825, 'n_words': 453}