<commit_before>/*
  mainwindow.cpp - Main implementation file of WildFox-Mimic.
  
  Revision 0
  
  Features:
        - 
        
  Notes:
        - Uses the JSON parser from http://ereilin.tumblr.com/post/6857765046/lightweight-json-parser-serializer-class-for-qt
        
  2011/11/22, <NAME>
  (c) Nyanko.ws
*/

#include "mainwindow.h"

#include <QtGui>
#include <QWebView>
#include <QtUiTools/QUiLoader>
#include <QDesktopServices>
#include <QNetworkProxyFactory>
#include <QList>

#include "iofile.h"
#include "optionsdialog.h"
#include "json.h"


// --- CONSTRUCTOR ---
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent) {
    setupUi(this);
    
    // menu connections
    connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
    connect(actionAbout_WildFox, SIGNAL(triggered()), this, SLOT(about()));
    connect(actionNewTab, SIGNAL(triggered()), this, SLOT(newTab()));
    connect(actionClose_Tab, SIGNAL(triggered()), this, SLOT(closeTab()));
    connect(actionOptions, SIGNAL(triggered()), this, SLOT(options()));
    
    // other interface connections
    connect(backButton, SIGNAL(pressed()), this, SLOT(back()));
    connect(forwardButton, SIGNAL(pressed()), this, SLOT(forward()));
    connect(reloadButton, SIGNAL(pressed()), this, SLOT(loadInteraction()));
    connect(actionReload, SIGNAL(triggered()), this, SLOT(reload()));
    connect(actionStop, SIGNAL(triggered()), this, SLOT(stop()));
    connect(addressBar, SIGNAL(returnPressed()), this, SLOT(gotoURL()));
    connect(addressBarGo, SIGNAL(pressed()), this, SLOT(gotoURL()));
    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int)));
    tabWidget->addAction(actionClose_Tab);
    connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    
    addAction(actionGo_to_address_bar);
    connect(actionGo_to_address_bar, SIGNAL(triggered()), this, SLOT(gotoAddressBar()));
    
    // defaults
    QCoreApplication::setOrganizationName("Nyanko");
    QCoreApplication::setOrganizationDomain("nyanko.ws");
    QCoreApplication::setApplicationName("WildFox");
    QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
    QNetworkProxy::setApplicationProxy(proxies[0]);
    wv = 0;
    icondb = "./";
    //cookies = new QNetworkCookieJar();
    cookiejar = new CookieJar();
    nam = new QNetworkAccessManager(this);
    nam->setCookieJar(cookiejar);
    stopbutton = false;
    QApplication::setActiveWindow(this);
    //settings = new QSettings("Nyanko", "WildFox");
    settings = new QSettings();
    storagePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    QDir dir(storagePath);
    if (!dir.exists()) {
        dir.mkpath(storagePath); // create path if it doesn't exist yet
    }
    
    qDebug() << "Storage path: " << storagePath;
    QWebSettings* ws = QWebSettings::globalSettings();
    ws->setAttribute(QWebSettings::PluginsEnabled, true);
    ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    ws->setIconDatabasePath(storagePath);
    
    // load any extensions. For each found extension, read in the JSON manifest
    // and create a WebPage object for background scripts and load the extension
    // into it. Register URL filters.
    // TESTING: XMarks extension is at ./extensions/xmarks/manifest.json
    QFile manifest("extensions/xmarks/manifest.json");
    if (!manifest.exists() || !manifest.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open the manifest file.";
    }
    else {
        QString manifestString = manifest.readAll();
        bool ok;
        QList<QString, QVariant> result;
        result = Json::parse(manifestString, ok).toMap();
        if (!ok) {
            qDebug() << "Parsing of manifest failed.";
        }
        
        if (result.contains("background_page")) {
            // load this extension into a webpage object.
        }
        
        if (result.contains("content_scripts")) {
            // add the content scripts in this list to the specified filters.
        }
    }
    
    // open empty tab
    newTab();
}


// --- DECONSTRUCTOR ---<commit_msg>Fixed small compile error in main window file.<commit_after>/*
  mainwindow.cpp - Main implementation file of WildFox-Mimic.
  
  Revision 0
  
  Features:
        - 
        
  Notes:
        - Uses the JSON parser from http://ereilin.tumblr.com/post/6857765046/lightweight-json-parser-serializer-class-for-qt
        
  2011/11/22, <NAME>
  (c) Nyanko.ws
*/

#include "mainwindow.h"

#include <QtGui>
#include <QWebView>
#include <QtUiTools/QUiLoader>
#include <QDesktopServices>
#include <QNetworkProxyFactory>
#include <QList>

#include "iofile.h"
#include "optionsdialog.h"
#include "json.h"


// --- CONSTRUCTOR ---
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent) {
    setupUi(this);
    
    // menu connections
    connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
    connect(actionAbout_WildFox, SIGNAL(triggered()), this, SLOT(about()));
    connect(actionNewTab, SIGNAL(triggered()), this, SLOT(newTab()));
    connect(actionClose_Tab, SIGNAL(triggered()), this, SLOT(closeTab()));
    connect(actionOptions, SIGNAL(triggered()), this, SLOT(options()));
    
    // other interface connections
    connect(backButton, SIGNAL(pressed()), this, SLOT(back()));
    connect(forwardButton, SIGNAL(pressed()), this, SLOT(forward()));
    connect(reloadButton, SIGNAL(pressed()), this, SLOT(loadInteraction()));
    connect(actionReload, SIGNAL(triggered()), this, SLOT(reload()));
    connect(actionStop, SIGNAL(triggered()), this, SLOT(stop()));
    connect(addressBar, SIGNAL(returnPressed()), this, SLOT(gotoURL()));
    connect(addressBarGo, SIGNAL(pressed()), this, SLOT(gotoURL()));
    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int)));
    tabWidget->addAction(actionClose_Tab);
    connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    
    addAction(actionGo_to_address_bar);
    connect(actionGo_to_address_bar, SIGNAL(triggered()), this, SLOT(gotoAddressBar()));
    
    // defaults
    QCoreApplication::setOrganizationName("Nyanko");
    QCoreApplication::setOrganizationDomain("nyanko.ws");
    QCoreApplication::setApplicationName("WildFox");
    QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
    QNetworkProxy::setApplicationProxy(proxies[0]);
    wv = 0;
    icondb = "./";
    //cookies = new QNetworkCookieJar();
    cookiejar = new CookieJar();
    nam = new QNetworkAccessManager(this);
    nam->setCookieJar(cookiejar);
    stopbutton = false;
    QApplication::setActiveWindow(this);
    //settings = new QSettings("Nyanko", "WildFox");
    settings = new QSettings();
    storagePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    QDir dir(storagePath);
    if (!dir.exists()) {
        dir.mkpath(storagePath); // create path if it doesn't exist yet
    }
    
    qDebug() << "Storage path: " << storagePath;
    QWebSettings* ws = QWebSettings::globalSettings();
    ws->setAttribute(QWebSettings::PluginsEnabled, true);
    ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    ws->setIconDatabasePath(storagePath);
    
    // load any extensions. For each found extension, read in the JSON manifest
    // and create a WebPage object for background scripts and load the extension
    // into it. Register URL filters.
    // TESTING: XMarks extension is at ./extensions/xmarks/manifest.json
    QFile manifest("extensions/xmarks/manifest.json");
    if (!manifest.exists() || !manifest.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open the manifest file.";
    }
    else {
        QString manifestString = manifest.readAll();
        bool ok;
        QMap<QString, QVariant> result;
        result = QtJson::Json::parse(manifestString, ok).toMap();
        if (!ok) {
            qDebug() << "Parsing of manifest failed.";
        }
        
        if (result.contains("background_page")) {
            // load this extension into a webpage object.
        }
        
        if (result.contains("content_scripts")) {
            // add the content scripts in this list to the specified filters.
        }
    }
    
    // open empty tab
    newTab();
}


// --- DECONSTRUCTOR ---
{'fraction_non_alphanumeric': 0.14153883029721956, 'fraction_numerical': 0.0050335570469798654, 'mean_word_length': 3.649025069637883, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, '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': '1147117', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2478, 'n_words': 533}