<commit_before>#include "timerwidget.h"
#include "ui_timerwidget.h"

#include <QApplication>

#include "toggl_api.h"

TimerWidget::TimerWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TimerWidget),
    timer(0),
    duration(0),
    timeEntryAutocompleteNeedsUpdate(false)
{
    ui->setupUi(this);

    connect(TogglApi::instance, SIGNAL(displayStoppedTimerState()),
            this, SLOT(displayStoppedTimerState()));
    connect(TogglApi::instance, SIGNAL(displayRunningTimerState(TimeEntryView*)),
            this, SLOT(displayRunningTimerState(TimeEntryView*)));

    connect(TogglApi::instance, SIGNAL(displayTimeEntryAutocomplete(QVector<AutocompleteView*>)),
            this, SLOT(displayTimeEntryAutocomplete(QVector<AutocompleteView*>)));

    connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
            this, SLOT(focusChanged(QWidget*,QWidget*)));

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
}

TimerWidget::~TimerWidget()
{
    timer->stop();

    delete ui;
}

void TimerWidget::focusChanged(QWidget *old, QWidget *now)
{
    if (old == ui->description && timeEntryAutocompleteNeedsUpdate)
    {
        displayTimeEntryAutocomplete(timeEntryAutocompleteUpdate);
    }
}

void TimerWidget::displayRunningTimerState(
    TimeEntryView *te)
{
    ui->start->setText("Stop");

    ui->description->setCurrentText(te->Description);
    ui->duration->setText(te->Duration);
    ui->project->setText(te->ProjectAndTaskLabel);

    duration = te->DurationInSeconds;

    disconnect(this, SLOT(start()));
    disconnect(this, SLOT(stop()));

    connect(this, SIGNAL(buttonClicked()), this, SLOT(stop()));

    timer->start(1000);
}

void TimerWidget::displayStoppedTimerState()
{
    ui->start->setText("Start");

    if (!ui->description->hasFocus())
    {
        ui->description->setCurrentText("");
    }
    if (!ui->duration->hasFocus())
    {
        ui->duration->setText("");

    }
    ui->project->setText("");

    duration = 0;

    disconnect(this, SLOT(start()));<commit_msg>Timer is readonly when time is ticking (linux)<commit_after>#include "timerwidget.h"
#include "ui_timerwidget.h"

#include <QApplication>

#include "toggl_api.h"

TimerWidget::TimerWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TimerWidget),
    timer(0),
    duration(0),
    timeEntryAutocompleteNeedsUpdate(false)
{
    ui->setupUi(this);

    connect(TogglApi::instance, SIGNAL(displayStoppedTimerState()),
            this, SLOT(displayStoppedTimerState()));
    connect(TogglApi::instance, SIGNAL(displayRunningTimerState(TimeEntryView*)),
            this, SLOT(displayRunningTimerState(TimeEntryView*)));

    connect(TogglApi::instance, SIGNAL(displayTimeEntryAutocomplete(QVector<AutocompleteView*>)),
            this, SLOT(displayTimeEntryAutocomplete(QVector<AutocompleteView*>)));

    connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
            this, SLOT(focusChanged(QWidget*,QWidget*)));

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
}

TimerWidget::~TimerWidget()
{
    timer->stop();

    delete ui;
}

void TimerWidget::focusChanged(QWidget *old, QWidget *now)
{
    if (old == ui->description && timeEntryAutocompleteNeedsUpdate)
    {
        displayTimeEntryAutocomplete(timeEntryAutocompleteUpdate);
    }
}

void TimerWidget::displayRunningTimerState(
    TimeEntryView *te)
{
    ui->start->setText("Stop");

    ui->description->setCurrentText(te->Description);
    ui->description->setEnabled(false);

    ui->duration->setText(te->Duration);
    ui->duration->setEnabled(false);

    ui->project->setText(te->ProjectAndTaskLabel);

    duration = te->DurationInSeconds;

    disconnect(this, SLOT(start()));
    disconnect(this, SLOT(stop()));

    connect(this, SIGNAL(buttonClicked()), this, SLOT(stop()));

    timer->start(1000);
}

void TimerWidget::displayStoppedTimerState()
{
    ui->start->setText("Start");

    if (!ui->description->hasFocus())
    {
        ui->description->setCurrentText("");
    }
    ui->description->setEnabled(true);

    if (!ui->duration->hasFocus())
    {
        ui->duration->setText("");
    }
    ui->duration->setEnabled(true);

    ui->project->setText("");

    duration = 0;

    disconnect(this, SLOT(start()));
{'fraction_non_alphanumeric': 0.15996301433194637, 'fraction_numerical': 0.003236245954692557, 'mean_word_length': 4.429109159347553, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 73, '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': '240017', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1315, 'n_words': 184}