<commit_before>//===========================================
//  Lumina Desktop Source Code
//  Copyright (c) 2016, <NAME>
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "page_session_options.h"
#include "ui_page_session_options.h"
#include "getPage.h"

//==========
//    PUBLIC
//==========
page_session_options::page_session_options(QWidget *parent) : PageWidget(parent), ui(new Ui::page_session_options()){
  ui->setupUi(this);
  loading = false;
  //Display formats for panel clock
  ui->combo_session_datetimeorder->clear();
  ui->combo_session_datetimeorder->addItem( tr("Time (Date as tooltip)"), "timeonly");
  ui->combo_session_datetimeorder->addItem( tr("Date (Time as tooltip)"), "dateonly");
  ui->combo_session_datetimeorder->addItem( tr("Time first then Date"), "timedate");
  ui->combo_session_datetimeorder->addItem( tr("Date first then Time"), "datetime");

  connect(ui->push_session_setUserIcon, SIGNAL(clicked()), this, SLOT(sessionChangeUserIcon()) );
  connect(ui->push_session_resetSysDefaults, SIGNAL(clicked()), this, SLOT(sessionResetSys()) );
  connect(ui->push_session_resetLuminaDefaults, SIGNAL(clicked()), this, SLOT(sessionResetLumina()) );
  connect(ui->tool_help_time, SIGNAL(clicked()), this, SLOT(sessionShowTimeCodes()) );
  connect(ui->tool_help_date, SIGNAL(clicked()), this, SLOT(sessionShowDateCodes()) );
  connect(ui->line_session_time, SIGNAL(textChanged(QString)), this, SLOT(sessionLoadTimeSample()) );
  connect(ui->line_session_date, SIGNAL(textChanged(QString)), this, SLOT(sessionLoadDateSample()) );
  connect(ui->combo_session_datetimeorder, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged()) );
  connect(ui->check_session_numlock, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_session_playloginaudio, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_session_playlogoutaudio, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_autoapplinks, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_watch_app_procs, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
 updateIcons();
 
}

page_session_options::~page_session_options(){

}

//================
//    PUBLIC SLOTS
//================
void page_session_options::SaveSettings(){
  QSettings sessionsettings("lumina-desktop","sessionsettings");
  sessionsettings.setValue("AutomaticDesktopAppLinks",  ui->check_autoapplinks->isChecked());
  sessionsettings.setValue("EnableNumlock", ui->check_session_numlock->isChecked());
  sessionsettings.setValue("PlayStartupAudio", ui->check_session_playloginaudio->isChecked());
  sessionsettings.setValue("PlayLogoutAudio", ui->check_session_playlogoutaudio->isChecked());
  sessionsettings.setValue("TimeFormat", ui->line_session_time->text());
  sessionsettings.setValue("DateFormat", ui->line_session_date->text());
  sessionsettings.setValue("DateTimeOrder", ui->combo_session_datetimeorder->currentData().toString());

  QString lopenWatchFile = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/nowatch";
  if(QFile::exists(lopenWatchFile) && ui->check_watch_app_procs->isChecked()){
    QFile::remove(lopenWatchFile);
  }else if(!QFile::exists(lopenWatchFile) && !ui->check_watch_app_procs->isChecked()){
    QFile file(lopenWatchFile);
    if(file.open(QIODevice::WriteOnly) ){ file.close(); } //just need to touch it to create the file
  }
  emit HasPendingChanges(false);
}

void page_session_options::LoadSettings(int){
  emit HasPendingChanges(false);
  emit ChangePageTitle( tr("Desktop Settings") );
  loading = true;
  QSettings sessionsettings("lumina-desktop","sessionsettings");
  ui->check_session_numlock->setChecked( sessionsettings.value("EnableNumlock", true).toBool() );
  ui->check_session_playloginaudio->setChecked( sessionsettings.value("PlayStartupAudio",true).toBool() );
  ui->check_session_playlogoutaudio->setChecked( sessionsettings.value("PlayLogoutAudio",true).toBool() );
  ui->check_autoapplinks->setChecked( sessionsettings.value("AutomaticDesktopAppLinks",true).toBool() );
  ui->push_session_setUserIcon->setIcon( LXDG::findIcon(QDir::homePath()+"/.loginIcon.png", "user-identity") );
  ui->line_session_time->setText( sessionsettings.value("TimeFormat","").toString() );
  ui->line_session_date->setText( sessionsettings.value("DateFormat","").toString() );
  int index = ui->combo_session_datetimeorder->findData( sessionsettings.value("DateTimeOrder","timeonly").toString() );
  ui->combo_session_datetimeorder->setCurrentIndex(index);

  QString lopenWatchFile = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/nowatch";
  ui->check_watch_app_procs->setChecked( !QFile::exists(lopenWatchFile) );

  sessionLoadTimeSample();
  sessionLoadDateSample();
  QApplication::processEvents(); //throw away any interaction events from loading
  loading = false;
}

void page_session_options::updateIcons(){
  ui->push_session_resetSysDefaults->setIcon( LXDG::findIcon("start-here-lumina","view-refresh") );
  ui->push_session_resetLuminaDefaults->setIcon( LXDG::findIcon("Lumina-DE","") );<commit_msg>Fix up the saving of the user's default icon via lumina-config.<commit_after>//===========================================
//  Lumina Desktop Source Code
//  Copyright (c) 2016, <NAME>
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "page_session_options.h"
#include "ui_page_session_options.h"
#include "getPage.h"

//==========
//    PUBLIC
//==========
page_session_options::page_session_options(QWidget *parent) : PageWidget(parent), ui(new Ui::page_session_options()){
  ui->setupUi(this);
  loading = false;
  //Display formats for panel clock
  ui->combo_session_datetimeorder->clear();
  ui->combo_session_datetimeorder->addItem( tr("Time (Date as tooltip)"), "timeonly");
  ui->combo_session_datetimeorder->addItem( tr("Date (Time as tooltip)"), "dateonly");
  ui->combo_session_datetimeorder->addItem( tr("Time first then Date"), "timedate");
  ui->combo_session_datetimeorder->addItem( tr("Date first then Time"), "datetime");

  connect(ui->push_session_setUserIcon, SIGNAL(clicked()), this, SLOT(sessionChangeUserIcon()) );
  connect(ui->push_session_resetSysDefaults, SIGNAL(clicked()), this, SLOT(sessionResetSys()) );
  connect(ui->push_session_resetLuminaDefaults, SIGNAL(clicked()), this, SLOT(sessionResetLumina()) );
  connect(ui->tool_help_time, SIGNAL(clicked()), this, SLOT(sessionShowTimeCodes()) );
  connect(ui->tool_help_date, SIGNAL(clicked()), this, SLOT(sessionShowDateCodes()) );
  connect(ui->line_session_time, SIGNAL(textChanged(QString)), this, SLOT(sessionLoadTimeSample()) );
  connect(ui->line_session_date, SIGNAL(textChanged(QString)), this, SLOT(sessionLoadDateSample()) );
  connect(ui->combo_session_datetimeorder, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged()) );
  connect(ui->check_session_numlock, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_session_playloginaudio, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_session_playlogoutaudio, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_autoapplinks, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
  connect(ui->check_watch_app_procs, SIGNAL(toggled(bool)), this, SLOT(settingChanged()) );
 updateIcons();
 
}

page_session_options::~page_session_options(){

}

//================
//    PUBLIC SLOTS
//================
void page_session_options::SaveSettings(){
  QSettings sessionsettings("lumina-desktop","sessionsettings");
  sessionsettings.setValue("AutomaticDesktopAppLinks",  ui->check_autoapplinks->isChecked());
  sessionsettings.setValue("EnableNumlock", ui->check_session_numlock->isChecked());
  sessionsettings.setValue("PlayStartupAudio", ui->check_session_playloginaudio->isChecked());
  sessionsettings.setValue("PlayLogoutAudio", ui->check_session_playlogoutaudio->isChecked());
  sessionsettings.setValue("TimeFormat", ui->line_session_time->text());
  sessionsettings.setValue("DateFormat", ui->line_session_date->text());
  sessionsettings.setValue("DateTimeOrder", ui->combo_session_datetimeorder->currentData().toString());

  QString lopenWatchFile = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/nowatch";
  if(QFile::exists(lopenWatchFile) && ui->check_watch_app_procs->isChecked()){
    QFile::remove(lopenWatchFile);
  }else if(!QFile::exists(lopenWatchFile) && !ui->check_watch_app_procs->isChecked()){
    QFile file(lopenWatchFile);
    if(file.open(QIODevice::WriteOnly) ){ file.close(); } //just need to touch it to create the file
  }

  //User Icon
  QString path = QDir::homePath()+"/.loginIcon.png"; //where the icon should be placed
  QString icopath = ui->push_session_setUserIcon->whatsThis();
  qDebug() << "User Icon:" << icopath;
  if(icopath != path && QFile::exists(icopath)){
    QPixmap ico(icopath);
    ico = ico.scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    bool ok = ico.save(path);
    qDebug() << "  - Saved User Icon:" << ok;
  }

  emit HasPendingChanges(false);
}

void page_session_options::LoadSettings(int){
  emit HasPendingChanges(false);
  emit ChangePageTitle( tr("Desktop Settings") );
  loading = true;
  QSettings sessionsettings("lumina-desktop","sessionsettings");
  ui->check_session_numlock->setChecked( sessionsettings.value("EnableNumlock", true).toBool() );
  ui->check_session_playloginaudio->setChecked( sessionsettings.value("PlayStartupAudio",true).toBool() );
  ui->check_session_playlogoutaudio->setChecked( sessionsettings.value("PlayLogoutAudio",true).toBool() );
  ui->check_autoapplinks->setChecked( sessionsettings.value("AutomaticDesktopAppLinks",true).toBool() );
  ui->push_session_setUserIcon->setIcon( LXDG::findIcon(QDir::homePath()+"/.loginIcon.png", "user-identity") );
  ui->line_session_time->setText( sessionsettings.value("TimeFormat","").toString() );
  ui->line_session_date->setText( sessionsettings.value("DateFormat","").toString() );
  int index = ui->combo_session_datetimeorder->findData( sessionsettings.value("DateTimeOrder","timeonly").toString() );
  ui->combo_session_datetimeorder->setCurrentIndex(index);

  QString lopenWatchFile = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/nowatch";
  ui->check_watch_app_procs->setChecked( !QFile::exists(lopenWatchFile) );

  sessionLoadTimeSample();
  sessionLoadDateSample();
  QApplication::processEvents(); //throw away any interaction events from loading
  loading = false;
}

void page_session_options::updateIcons(){
  ui->push_session_resetSysDefaults->setIcon( LXDG::findIcon("start-here-lumina","view-refresh") );
  ui->push_session_resetLuminaDefaults->setIcon( LXDG::findIcon("Lumina-DE","") );
{'fraction_non_alphanumeric': 0.1793647879566734, 'fraction_numerical': 0.0012851110703139342, 'mean_word_length': 7.930327868852459, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 139, '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': '2495894', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3380, 'n_words': 487}