<commit_before>/*=============================================================*/
/* SECTION: Includes                                           */
/*=============================================================*/

#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <psapi.h>
#include <QDesktopWidget>

#include <Qt>

#include <QKeyEvent>
#include <QMessageBox>
#include <QShortcut>
#include <QHash>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "cmdformatter.h"

/*=============================================================*/
/* SECTION: Local Data                                         */
/*=============================================================*/

/// Stores saved alias windows.
QHash<HWND, QString> gSavedWins;

/// The application version string.
QString gVerStr("0.5.0-alpha");

/*=============================================================*/
/* SECTION: Local Prototypes                                   */
/*=============================================================*/

static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
static BOOL IsAltTabWindow(HWND hwnd);

/*=============================================================*/
/* SECTION: Function Definitions                               */
/*=============================================================*/

MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        proxy(new QSortFilterProxyModel(parent)),
        model(new QStandardItemModel(0, 4, parent))
{
    // Set the window style.
    Qt::WindowFlags flags = windowFlags();
    setWindowFlags(flags | Qt::WindowStaysOnTopHint | Qt::ToolTip);

    // Set up system tray.
    trayIconMenu = new QMenu(this);
    aboutAction = new QAction(tr("&About"), this);
    quitAction = new QAction(tr("&Quit"), this);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutMain()));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(quitMain()));
    trayIconMenu->addAction(aboutAction);
    trayIconMenu->addAction(quitAction);
    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(trayIconMenu);
    trayIcon->setToolTip(QString("QuickWin"));
    trayIcon->setIcon(QIcon("icon.png"));
    trayIcon->show();

    // Set up UI items.
    ui->setupUi(this);
    proxy->setSourceModel(model);
    ui->winView->setModel(proxy);
    proxy->setFilterKeyColumn(1);
    ui->winView->setSortingEnabled(true);
    ui->winView->sortByColumn(0, Qt::AscendingOrder);
    ui->winView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Number"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Title"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Executable"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("Alias"));
    sizePosMain();

    connect(ui->cmdText, SIGNAL(returnPressed()),
            this,SLOT(onTextEnter()));
    connect(ui->cmdText, SIGNAL(textChanged(const QString &)),
            this, SLOT(onTextChanged(const QString &)));
    connect(ui->winView, SIGNAL(activated(QModelIndex)),
            this, SLOT(onWitemActivate(QModelIndex)));

    // Register system-wide hotkey.
    HWND hwnd = (HWND)this->winId();
    RegisterHotKey(hwnd, 100, MOD_CONTROL | MOD_ALT, VK_SPACE);

    updateWinList(true);
}

void MainWindow::sizePosMain(void) {
    // Center window.
    QDesktopWidget *desktop = QApplication::desktop();
    int width = desktop->width() * 0.6;
    int height = desktop->height() * 0.6;
    setFixedSize(width, height);
    move((desktop->width() - width) / 2, (desktop->height() - height) / 2);

    ui->winView->header()->resizeSection(0, width * 0.08);
    ui->winView->header()->resizeSection(1, width * 0.7);
}

void MainWindow::aboutMain(void) {
    QMessageBox::about(this,
            "About QuickWin",
            "QuickWin version `" + gVerStr + "`.\nVisit 'github.com/jeffrimko/QuickWin' for more information.");
}

void MainWindow::quitMain(void) {
    exit(0);
}

void MainWindow::updateWinList(bool clear_note) {<commit_msg>Will only display on the primary monitor now.<commit_after>/*=============================================================*/
/* SECTION: Includes                                           */
/*=============================================================*/

#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <psapi.h>
#include <QDesktopWidget>

#include <Qt>

#include <QKeyEvent>
#include <QMessageBox>
#include <QShortcut>
#include <QHash>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "cmdformatter.h"

/*=============================================================*/
/* SECTION: Local Data                                         */
/*=============================================================*/

/// Stores saved alias windows.
QHash<HWND, QString> gSavedWins;

/// The application version string.
QString gVerStr("0.5.0-alpha");

/*=============================================================*/
/* SECTION: Local Prototypes                                   */
/*=============================================================*/

static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
static BOOL IsAltTabWindow(HWND hwnd);

/*=============================================================*/
/* SECTION: Function Definitions                               */
/*=============================================================*/

MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        proxy(new QSortFilterProxyModel(parent)),
        model(new QStandardItemModel(0, 4, parent))
{
    // Set the window style.
    Qt::WindowFlags flags = windowFlags();
    setWindowFlags(flags | Qt::WindowStaysOnTopHint | Qt::ToolTip);

    // Set up system tray.
    trayIconMenu = new QMenu(this);
    aboutAction = new QAction(tr("&About"), this);
    quitAction = new QAction(tr("&Quit"), this);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutMain()));
    connect(quitAction, SIGNAL(triggered()), this, SLOT(quitMain()));
    trayIconMenu->addAction(aboutAction);
    trayIconMenu->addAction(quitAction);
    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(trayIconMenu);
    trayIcon->setToolTip(QString("QuickWin"));
    trayIcon->setIcon(QIcon("icon.png"));
    trayIcon->show();

    // Set up UI items.
    ui->setupUi(this);
    proxy->setSourceModel(model);
    ui->winView->setModel(proxy);
    proxy->setFilterKeyColumn(1);
    ui->winView->setSortingEnabled(true);
    ui->winView->sortByColumn(0, Qt::AscendingOrder);
    ui->winView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("Number"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Title"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Executable"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("Alias"));
    sizePosMain();

    connect(ui->cmdText, SIGNAL(returnPressed()),
            this,SLOT(onTextEnter()));
    connect(ui->cmdText, SIGNAL(textChanged(const QString &)),
            this, SLOT(onTextChanged(const QString &)));
    connect(ui->winView, SIGNAL(activated(QModelIndex)),
            this, SLOT(onWitemActivate(QModelIndex)));

    // Register system-wide hotkey.
    HWND hwnd = (HWND)this->winId();
    RegisterHotKey(hwnd, 100, MOD_CONTROL | MOD_ALT, VK_SPACE);

    updateWinList(true);
}

void MainWindow::sizePosMain(void) {
    // Center window.
    QDesktopWidget *desktop = QApplication::desktop();
    int width = desktop->screenGeometry(desktop->primaryScreen()).width() * 0.6;
    int height = desktop->screenGeometry(desktop->primaryScreen()).height() * 0.6;
    setFixedSize(width, height);
    move(
            (desktop->screenGeometry(desktop->primaryScreen()).width() - width) / 2,
            (desktop->screenGeometry(desktop->primaryScreen()).height() - height) / 2
        );

    ui->winView->header()->resizeSection(0, width * 0.08);
    ui->winView->header()->resizeSection(1, width * 0.7);
}

void MainWindow::aboutMain(void) {
    QMessageBox::about(this,
            "About QuickWin",
            "QuickWin version `" + gVerStr + "`.\nVisit 'github.com/jeffrimko/QuickWin' for more information.");
}

void MainWindow::quitMain(void) {
    exit(0);
}

void MainWindow::updateWinList(bool clear_note) {
{'fraction_non_alphanumeric': 0.2567663817663818, 'fraction_numerical': 0.008309591642924977, 'mean_word_length': 4.005941770647653, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2178785', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2382, 'n_words': 432}