Logo Search packages:      
Sourcecode: shutdown-qapps version File versions  Download package

preferences.cpp

/* qshutdown, a program to shutdown/reboot/suspend/hibernate the system
 * Copyright (C) 2009 2010  Christian Metscher <hakaishi@web.de>

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "preferences.h"

extern bool timeRunning; //varibale declared in gui.cpp

Preferences::Preferences(QWidget *parent): QDialog(parent){

      setupUi(this);

     setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Window);    //always in front

/***************** load settings from the conf file *****************/

#ifdef Q_OS_WIN32
     file = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/qshutdown/qshutdown.conf";
     settings = new QSettings(file, QSettings::IniFormat);
#else //!Q_OS_WIN32
     file = QDir::homePath() + "/.qshutdown/qshutdown.conf";
     settings = new QSettings(file, QSettings::IniFormat);
#endif //Q_OS_WIN32

     msgBox = new QMessageBox(this);
     msgBox->setWindowTitle("Error");
     msgBox->setIcon(QMessageBox::Warning);
     msgBox->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Window);
     msgBox->setInformativeText(tr("The File \"") + file + tr("\" is not writeable!\n"
     "Maybe you just don't have the permissions to do so."));
     QTimer::singleShot(15000, msgBox, SLOT(close()));

     connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveToConfFile()));
     connect(reset, SIGNAL(clicked(bool)), this, SLOT(resetSettings()));
}

Preferences::~Preferences(){ delete settings; }

void Preferences::showEvent(QShowEvent* show_pref){
     loadSettings();
     starting();
     if(!settings->isWritable())
       msgBox->show();
     QDialog::showEvent(show_pref);
}

void Preferences::loadSettings(){
     comboBox->setCurrentIndex(settings->value("Power/comboBox").toInt());
     timeEdit->setTime(QTime(settings->value("Time/time_hour").toInt(),settings->value("Time/time_minute").toInt()));
     spin->setValue(settings->value("Time/countdown_minutes").toInt());
     font1Spin->setValue(settings->value("Fonts/font1").toInt());
     font2Spin->setValue(settings->value("Fonts/font2").toInt());
     font3Spin->setValue(settings->value("Fonts/font3").toInt());
     radio1->setChecked(settings->value("CheckBoxes/target_time").toBool());
     radio2->setChecked(settings->value("CheckBoxes/countdown").toBool());
     lock->setChecked(settings->value("CheckBoxes/lock").toBool());
     warn->setChecked(settings->value("CheckBoxes/warnings").toBool());
     log->setChecked(settings->value("Logfile/logging").toBool());
}

void Preferences::saveToConfFile(){
     if(settings->isWritable()){
       settings->setValue("Power/comboBox", comboBox->currentIndex());
       settings->setValue("Time/time_hour", timeEdit->time().hour());
       settings->setValue("Time/time_minute", timeEdit->time().minute());
       settings->setValue("Time/countdown_minutes", spin->value());
       settings->setValue("Fonts/font1", font1Spin->value());
       settings->setValue("Fonts/font2", font2Spin->value());
       settings->setValue("Fonts/font3", font3Spin->value());
       settings->setValue("CheckBoxes/target_time", radio1->isChecked());
       settings->setValue("CheckBoxes/countdown", radio2->isChecked());
       settings->setValue("CheckBoxes/lock", lock->isChecked());
       settings->setValue("CheckBoxes/warnings", warn->isChecked());
       settings->setValue("Logfile/logging", log->isChecked());
     }
}

void Preferences::resetSettings(){
     if(settings->isWritable()){
       comboBox->setCurrentIndex(0);
       timeEdit->setTime(QTime(22,00));
       spin->setValue(60);
       font1Spin->setValue(13);
       font2Spin->setValue(18);
       font3Spin->setValue(11);
       radio1->setChecked(false);
       radio2->setChecked(true);
       lock->setChecked(true);
       warn->setChecked(true);
       log->setChecked(false);
     }
}

void Preferences::closeEvent(QCloseEvent* window_close){
     if(!timeRunning)
       finishing();
     QDialog::closeEvent(window_close);
}

Generated by  Doxygen 1.6.0   Back to index