<commit_before>/* -*- coding: utf-8 -*-
*   Copyright (c) 2010, <NAME>.  This file is
*   licensed under the General Public License version 3 or later.
*   See the COPYRIGHT file.
*/

#include "mainwindow.h"

MainWindow::MainWindow( QStringList list, QWidget *parent )
    : QMainWindow( parent ) {
    loadSettings ();

    setWindowTitle( tr( "%1 -- For better use of leo.org" ).arg( QCoreApplication::applicationName()));

    createBars();
    createSystemTray();

    url = "http://pda.leo.org/";

    // Remove the path item of the argv-list
    list.removeFirst();
    para = list.join(" ");

    view = new QWebView;
        view->load( QString("%1%2%3" ).arg( url ).arg( loadINI ()).arg( para ));
    setCentralWidget( view );

    connect( view, SIGNAL( loadStarted ()), this, SLOT( show ()));
    connect( view, SIGNAL( loadProgress ( int )), this, SLOT( progressLoad ( int )));
    connect( view, SIGNAL( loadFinished ( bool )), this, SLOT( finishedLoad ( bool )));

    clipboard = QApplication::clipboard ();
        connect(clipboard,SIGNAL( changed( QClipboard::Mode )), this, SLOT( clipboardChange ()));
}

MainWindow::~MainWindow() {
    writeSettings ();
}

void MainWindow::loadSettings() {
    QSettings settings;

    settings.beginGroup ( "MainWindow" );
    resize(settings.value ( "Size", QSize( 400, 600 )).toSize ());
    move(settings.value ( "Pos", QPoint( 100, 100 )).toPoint ());
    settings.endGroup ();
}

void MainWindow::writeSettings() {
    QSettings settings;

    settings.beginGroup ( "MainWindow" );
    settings.setValue ( "Size", size());
    settings.setValue ( "Pos", pos ());
    settings.endGroup ();
}

void MainWindow::createBars() {
    createActions();

    qpbMain = new QProgressBar;
        qpbMain->setMaximumSize( 150, 15 );
        qpbMain->setTextVisible( 0 );

    setStatusBar(qsbMain = new QStatusBar);
        qsbMain->showMessage( tr( "Ready" ));
        qsbMain->addPermanentWidget( qpbMain );

    setMenuBar( qmbMain = new QMenuBar );
        qmbMain->addMenu( qmFile = new QMenu( tr( "&File" )));
            qmFile->addSeparator();
            qmFile->addAction( qaPrintDialog );
            qmFile->addSeparator();
            qmFile->addAction( qaExit );
        qmbMain->addMenu( qmEdit = new QMenu( tr( "&Edit" )));
            qmEdit->addActions( qagNavigation->actions ());
            qmEdit->addAction( qaSearch );
            qmEdit->addMenu (qmSubEdit = new QMenu( tr( "Languages" )));
                qmSubEdit->addActions (qagLanguages->actions ());
        qmbMain->addMenu( qmView = new QMenu( tr( "&View" )));
            qmView->addActions ( qagZoom->actions ());
        qmbMain->addMenu( qmHelp = new QMenu( tr( "&Help" )));
            qmHelp->addAction( qaAboutQt );
            qmHelp->addSeparator();
            qmHelp->addAction( qaAbout );

    qtbDeleteSearch = new QToolButton(this);
	qtbDeleteSearch->setDefaultAction( qaClearSearch );

    qleSearch = new QLineEdit;
        connect( qleSearch, SIGNAL( returnPressed()), this, SLOT( lineSearch()));
#if ( QT_VERSION >= 0x040700 )
        qleSearch->setPlaceholderText( tr( "Search" ));
#endif

    qtbMain = new QToolBar( "Toolbar" );
	qtbMain->setFloatable( false );
	qtbMain->setMovable( false );
        qtbMain->addAction( qaHome );
        qtbMain->addSeparator();
        qtbMain->addActions( qagNavigation->actions ());
	qtbMain->addSeparator();
	qtbMain->addWidget( qtbDeleteSearch );
        qtbMain->addWidget( qleSearch );
        addToolBar( qtbMain );
}

void MainWindow::createActions() {
    qaHome = new QAction( IconLoader::Load( "go-home" ), tr( "Home" ), this );

        qaHome->setShortcut( Qt::ControlModifier + Qt::Key_H );
        qaHome->setStatusTip( tr( "Click to go home" ));

    qaExit = new QAction( IconLoader::Load( "system-shutdown" ), tr( "&Exit" ), this);
        qaExit->setShortcut( QKeySequence::Quit );
        qaExit->setStatusTip( tr( "Exit the application" ));
        connect( qaExit, SIGNAL( triggered()), qApp, SLOT( quit()));

    qaBack = new QAction( IconLoader::Load( "go-previous" ), tr( "Back" ), this);
        qaBack->setShortcut( Qt::ControlModifier + Qt::Key_Left );
        qaBack->setStatusTip(  tr( "Click to go back" ));

    qaForward = new QAction( IconLoader::Load( "go-next" ), tr( "Forward" ), this );
        qaForward->setShortcut( Qt::ControlModifier + Qt::Key_Right );
        qaForward->setStatusTip( tr( "Click to go forward" ));

    qaStop = new QAction( IconLoader::Load( "process-stop" ), tr( "Stop" ), this);
        qaStop->setShortcut( Qt::Key_Escape );
        qaStop->setStatusTip( tr( "Click to go stop" ));

    qaReload = new QAction( IconLoader::Load( "view-refresh" ), tr( "Reload" ), this );
        qaReload->setShortcut( QKeySequence::Refresh );
        qaReload->setStatusTip( tr( "Click to go reload" ));

     qaAbout = new QAction( IconLoader::Load( "help-about" ), tr( "&About" ), this );
        qaAbout->setStatusTip( tr( "About the application" ));
        connect( qaAbout, SIGNAL( triggered()), this, SLOT( about()));

    qaAboutQt = new QAction( tr( "About &Qt" ), this);
        qaAboutQt->setStatusTip( tr( "About the Qt version" ));
        connect( qaAboutQt, SIGNAL( triggered()), qApp, SLOT( aboutQt()));

    qagNavigation = new QActionGroup( this );
        qagNavigation->addAction ( qaHome );
        qagNavigation->addAction ( qaBack );
        qagNavigation->addAction ( qaReload );
        qagNavigation->addAction ( qaForward );
        qagNavigation->addAction ( qaStop );
        connect ( qagNavigation, SIGNAL( triggered( QAction* )), this, SLOT( navigationActionTriggered( QAction* )));

    qaSearch = new QAction( IconLoader::Load( "edit-find" ), tr( "Search" ), this );
        qaSearch->setShortcut( QKeySequence::Find );
        qaSearch->setStatusTip( tr( "Search words" ));
        connect( qaSearch, SIGNAL( triggered()), this, SLOT( search()));

    qaClearSearch = new QAction( IconLoader::Load( "edit-find" ), "", this );
        qaClearSearch->setStatusTip( tr( "Clear search words" ));
        connect( qaClearSearch, SIGNAL( triggered()), this, SLOT( clearSearch ()));

    qaPrintDialog = new QAction( IconLoader::Load ( "document-print-preview" ), tr ( "Print" ), this );
        qaPrintDialog->setShortcut( QKeySequence::Print );
        qaPrintDialog->setStatusTip( tr( "Print Preview" ));
        connect( qaPrintDialog, SIGNAL( triggered ()), this, SLOT( printpreview ()));

    qaZoomIn = new QAction( IconLoader::Load ( "zoom-in" ), tr( "Zoom &In" ), this );
        qaZoomIn->setShortcut( QKeySequence::ZoomIn );
        qaZoomIn->setStatusTip( tr ( "Zoom in of the page" ));

    qaZoomOut = new QAction( IconLoader::Load( "zoom-out" ), tr( "Zoom &Out" ), this );
        qaZoomOut->setShortcut( QKeySequence::ZoomOut );
        qaZoomOut->setStatusTip( tr( "Zoom out of the page" ));

   qaZoomNormal = new QAction( IconLoader::Load( "zoom-original" ), tr( "Zoom &Normal" ), this );
        qaZoomNormal->setShortcut( QKeySequence( "CTRL+0" ));
        qaZoomNormal->setStatusTip( tr( "Zoom normal of the page" ));

    qagZoom = new QActionGroup( this );
        qagZoom->addAction ( qaZoomIn );
        qagZoom->addAction ( qaZoomNormal );
        qagZoom->addAction ( qaZoomOut );
        connect ( qagZoom, SIGNAL( triggered( QAction* )), this, SLOT( zoomActionTriggered( QAction* )));

    qaEnglish = new QAction( QIcon( ":/flags/en.svg" ), tr( "English" ), this );
        qaEnglish->setCheckable(true);
    qaSpanish = new QAction( QIcon( ":/flags/es.svg" ), tr( "Spanish" ), this );
        qaSpanish->setCheckable(true);
    qaFrench = new QAction( QIcon( ":/flags/fr.svg" ), tr( "French" ), this );
        qaFrench->setCheckable(true);
    qaItalian = new QAction( QIcon( ":/flags/it.svg" ), tr( "Italian" ), this );
            qaItalian->setCheckable(true);
    qaChinese = new QAction( QIcon( ":/flags/cn.svg" ), tr( "Chinese" ), this );
        qaChinese->setCheckable(true);
    qaRussian = new QAction( QIcon( ":/flags/ru.svg" ), tr( "Russian" ), this );
            qaRussian->setCheckable(true);

    qagLanguages = new QActionGroup( this );
        qagLanguages->addAction ( qaEnglish );
        qagLanguages->addAction ( qaSpanish );
        qagLanguages->addAction ( qaFrench );
        qagLanguages->addAction ( qaItalian );
        qagLanguages->addAction ( qaChinese );
        qagLanguages->addAction ( qaRussian );
        connect( qagLanguages, SIGNAL( triggered( QAction* )), this, SLOT( languageActionTriggered( QAction* )));

}

void MainWindow::languageActionTriggered( QAction *action ) {
    QSettings settings;
    settings.beginGroup ( QCoreApplication::applicationName ());
    if( action == qaEnglish ){
        settings.setValue ( "Language", "?lp=ende&search=" );
    }
    else if( action == qaSpanish ) {
        settings.setValue ( "Language", "?lp=esde&search=" );
    }
    else if( action == qaFrench ) {
        settings.setValue ( "Language", "?lp=frde&search=" );
    }
    else if( action == qaItalian ) {
        settings.setValue ( "Language", "?lp=itde&search=" );
    }
    else if( action == qaChinese ) {<commit_msg>coding style<commit_after>/* -*- coding: utf-8 -*-
*   Copyright (c) 2010, <NAME>.  This file is
*   licensed under the General Public License version 3 or later.
*   See the COPYRIGHT file.
*/

#include "mainwindow.h"

MainWindow::MainWindow( QStringList list, QWidget *parent )
    : QMainWindow( parent ) {
    loadSettings ();

    setWindowTitle( tr( "%1 -- For better use of leo.org" ).arg( QCoreApplication::applicationName()));

    createBars();
    createSystemTray();

    url = "http://pda.leo.org/";

    // Remove the path item of the argv-list
    list.removeFirst();
    para = list.join(" ");

    view = new QWebView;
        view->load( QString("%1%2%3" ).arg( url ).arg( loadINI ()).arg( para ));
    setCentralWidget( view );

    connect( view, SIGNAL( loadStarted ()), this, SLOT( show ()));
    connect( view, SIGNAL( loadProgress ( int )), this, SLOT( progressLoad ( int )));
    connect( view, SIGNAL( loadFinished ( bool )), this, SLOT( finishedLoad ( bool )));

    clipboard = QApplication::clipboard ();
        connect(clipboard,SIGNAL( changed( QClipboard::Mode )), this, SLOT( clipboardChange ()));
}

MainWindow::~MainWindow() {
    writeSettings ();
}

void MainWindow::loadSettings() {
    QSettings settings;

    settings.beginGroup ( "MainWindow" );
    resize(settings.value ( "Size", QSize( 400, 600 )).toSize ());
    move(settings.value ( "Pos", QPoint( 100, 100 )).toPoint ());
    settings.endGroup ();
}

void MainWindow::writeSettings() {
    QSettings settings;

    settings.beginGroup ( "MainWindow" );
    settings.setValue ( "Size", size());
    settings.setValue ( "Pos", pos ());
    settings.endGroup ();
}

void MainWindow::createBars() {
    createActions();

    qpbMain = new QProgressBar;
        qpbMain->setMaximumSize( 150, 15 );
        qpbMain->setTextVisible( 0 );

    setStatusBar(qsbMain = new QStatusBar);
        qsbMain->showMessage( tr( "Ready" ));
        qsbMain->addPermanentWidget( qpbMain );

    setMenuBar( qmbMain = new QMenuBar );
        qmbMain->addMenu( qmFile = new QMenu( tr( "&File" )));
            qmFile->addSeparator();
            qmFile->addAction( qaPrintDialog );
            qmFile->addSeparator();
            qmFile->addAction( qaExit );
        qmbMain->addMenu( qmEdit = new QMenu( tr( "&Edit" )));
            qmEdit->addActions( qagNavigation->actions ());
            qmEdit->addAction( qaSearch );
            qmEdit->addMenu (qmSubEdit = new QMenu( tr( "Languages" )));
                qmSubEdit->addActions (qagLanguages->actions ());
        qmbMain->addMenu( qmView = new QMenu( tr( "&View" )));
            qmView->addActions ( qagZoom->actions ());
        qmbMain->addMenu( qmHelp = new QMenu( tr( "&Help" )));
            qmHelp->addAction( qaAboutQt );
            qmHelp->addSeparator();
            qmHelp->addAction( qaAbout );

    qtbDeleteSearch = new QToolButton(this);
	qtbDeleteSearch->setDefaultAction( qaClearSearch );

    qleSearch = new QLineEdit;
        connect( qleSearch, SIGNAL( returnPressed()), this, SLOT( lineSearch()));
#if ( QT_VERSION >= 0x040700 )
        qleSearch->setPlaceholderText( tr( "Search" ));
#endif

    qtbMain = new QToolBar( "Toolbar" );
	qtbMain->setFloatable( false );
	qtbMain->setMovable( false );
        qtbMain->addAction( qaHome );
        qtbMain->addSeparator();
        qtbMain->addActions( qagNavigation->actions ());
	qtbMain->addSeparator();
	qtbMain->addWidget( qtbDeleteSearch );
        qtbMain->addWidget( qleSearch );
        addToolBar( qtbMain );
}

void MainWindow::createActions() {
    qaHome = new QAction( IconLoader::Load( "go-home" ), tr( "Home" ), this );

        qaHome->setShortcut( Qt::ControlModifier + Qt::Key_H );
        qaHome->setStatusTip( tr( "Click to go home" ));

    qaExit = new QAction( IconLoader::Load( "system-shutdown" ), tr( "&Exit" ), this);
        qaExit->setShortcut( QKeySequence::Quit );
        qaExit->setStatusTip( tr( "Exit the application" ));
        connect( qaExit, SIGNAL( triggered()), qApp, SLOT( quit()));

    qaBack = new QAction( IconLoader::Load( "go-previous" ), tr( "Back" ), this);
        qaBack->setShortcut( Qt::ControlModifier + Qt::Key_Left );
        qaBack->setStatusTip(  tr( "Click to go back" ));

    qaForward = new QAction( IconLoader::Load( "go-next" ), tr( "Forward" ), this );
        qaForward->setShortcut( Qt::ControlModifier + Qt::Key_Right );
        qaForward->setStatusTip( tr( "Click to go forward" ));

    qaStop = new QAction( IconLoader::Load( "process-stop" ), tr( "Stop" ), this);
        qaStop->setShortcut( Qt::Key_Escape );
        qaStop->setStatusTip( tr( "Click to go stop" ));

    qaReload = new QAction( IconLoader::Load( "view-refresh" ), tr( "Reload" ), this );
        qaReload->setShortcut( QKeySequence::Refresh );
        qaReload->setStatusTip( tr( "Click to go reload" ));

     qaAbout = new QAction( IconLoader::Load( "help-about" ), tr( "&About" ), this );
        qaAbout->setStatusTip( tr( "About the application" ));
        connect( qaAbout, SIGNAL( triggered()), this, SLOT( about()));

    qaAboutQt = new QAction( tr( "About &Qt" ), this);
        qaAboutQt->setStatusTip( tr( "About the Qt version" ));
        connect( qaAboutQt, SIGNAL( triggered()), qApp, SLOT( aboutQt()));

    qagNavigation = new QActionGroup ( this );
        qagNavigation->addAction ( qaHome );
        qagNavigation->addAction ( qaBack );
        qagNavigation->addAction ( qaReload );
        qagNavigation->addAction ( qaForward );
        qagNavigation->addAction ( qaStop );
        connect ( qagNavigation, SIGNAL( triggered( QAction* )), this, SLOT( navigationActionTriggered( QAction* )));

    qaSearch = new QAction ( IconLoader::Load ( "edit-find" ), tr ( "Search" ), this );
        qaSearch->setShortcut ( QKeySequence::Find );
        qaSearch->setStatusTip ( tr( "Search words" ));
        connect( qaSearch, SIGNAL( triggered()), this, SLOT( search()));

    qaClearSearch = new QAction ( IconLoader::Load ( "edit-find" ), "", this );
        qaClearSearch->setStatusTip( tr ( "Clear search words" ));
        connect( qaClearSearch, SIGNAL( triggered()), this, SLOT( clearSearch ()));

    qaPrintDialog = new QAction( IconLoader::Load ( "document-print-preview" ), tr ( "Print" ), this );
        qaPrintDialog->setShortcut( QKeySequence::Print );
        qaPrintDialog->setStatusTip( tr ( "Print Preview" ));
        connect( qaPrintDialog, SIGNAL( triggered ()), this, SLOT( printpreview ()));

    qaZoomIn = new QAction( IconLoader::Load ( "zoom-in" ), tr ( "Zoom &In" ), this );
        qaZoomIn->setShortcut( QKeySequence::ZoomIn );
        qaZoomIn->setStatusTip( tr ( "Zoom in of the page" ));

    qaZoomOut = new QAction( IconLoader::Load( "zoom-out" ), tr ( "Zoom &Out" ), this );
        qaZoomOut->setShortcut( QKeySequence::ZoomOut );
        qaZoomOut->setStatusTip( tr( "Zoom out of the page" ));

   qaZoomNormal = new QAction( IconLoader::Load( "zoom-original" ), tr ( "Zoom &Normal" ), this );
        qaZoomNormal->setShortcut( QKeySequence( "CTRL+0" ));
        qaZoomNormal->setStatusTip( tr ( "Zoom normal of the page" ));

    qagZoom = new QActionGroup( this );
        qagZoom->addAction ( qaZoomIn );
        qagZoom->addAction ( qaZoomNormal );
        qagZoom->addAction ( qaZoomOut );
        connect ( qagZoom, SIGNAL( triggered( QAction* )), this, SLOT( zoomActionTriggered( QAction* )));

    qaEnglish = new QAction( QIcon( ":/flags/en.svg" ), tr( "English" ), this );
        qaEnglish->setCheckable( true );
    qaSpanish = new QAction( QIcon( ":/flags/es.svg" ), tr( "Spanish" ), this );
        qaSpanish->setCheckable( true );
    qaFrench = new QAction( QIcon( ":/flags/fr.svg" ), tr( "French" ), this );
        qaFrench->setCheckable( true );
    qaItalian = new QAction( QIcon( ":/flags/it.svg" ), tr( "Italian" ), this );
            qaItalian->setCheckable( true ;
    qaChinese = new QAction( QIcon( ":/flags/cn.svg" ), tr( "Chinese" ), this );
        qaChinese->setCheckable( true );
    qaRussian = new QAction( QIcon( ":/flags/ru.svg" ), tr( "Russian" ), this );
            qaRussian->setCheckable( true );

    qagLanguages = new QActionGroup( this );
        qagLanguages->addAction ( qaEnglish );
        qagLanguages->addAction ( qaSpanish );
        qagLanguages->addAction ( qaFrench );
        qagLanguages->addAction ( qaItalian );
        qagLanguages->addAction ( qaChinese );
        qagLanguages->addAction ( qaRussian );
        connect( qagLanguages, SIGNAL( triggered( QAction* )), this, SLOT( languageActionTriggered( QAction* )));

}

void MainWindow::languageActionTriggered( QAction *action ) {
    QSettings settings;
    settings.beginGroup ( QCoreApplication::applicationName ());
    if( action == qaEnglish ){
        settings.setValue ( "Language", "?lp=ende&search=" );
    }
    else if( action == qaSpanish ) {
        settings.setValue ( "Language", "?lp=esde&search=" );
    }
    else if( action == qaFrench ) {
        settings.setValue ( "Language", "?lp=frde&search=" );
    }
    else if( action == qaItalian ) {
        settings.setValue ( "Language", "?lp=itde&search=" );
    }
    else if( action == qaChinese ) {
{'fraction_non_alphanumeric': 0.15773128473357306, 'fraction_numerical': 0.003922850604772802, 'mean_word_length': 3.1640199637023594, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 167, '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': '2597013', 'n_tokens_mistral': 6079, 'n_tokens_neox': 5797, 'n_words': 1355}