File: preferences.cpp

package info (click to toggle)
shutdown-qapps 1.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,640 kB
  • sloc: cpp: 3,967; makefile: 10; sh: 1
file content (107 lines) | stat: -rw-r--r-- 4,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* qprogram-starter, a program to start programs or commands, with
   the option to log output and errors and to shutdown the system.
 * Copyright (C) 2010-2019 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"
#include <QDir>
#include <QTimer>
#include <QFile>
#include <QDesktopServices>

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

     setupUi(this);

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

     setupMsgBoxes();

     loadSettings();

     connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveToConfFile()));
}

void Preferences::setupMsgBoxes(){
     msgBox = new QMessageBox(this);
     msgBox->setWindowTitle(tr("Error"));
     msgBox->setIcon(QMessageBox::Warning);
     msgBox->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Window);
     msgBox->setInformativeText(tr("The File \"%1\" is not writable!\n"
       "Maybe you just don't have the permissions to do so.").arg(settings->fileName()));

     if(settings->value("first_start", true).toBool())
     {
       infoBox = new QMessageBox(this);
       infoBox->setWindowTitle(tr("Please read this carefully!"));
       infoBox->setIcon(QMessageBox::Information);
       infoBox->setInformativeText(tr("Welcome to qprogram-starter!\n"
         "If you want qprogram-starter to automatically shutdown the system "
         "and you are using the Gnome Shell, then you are likely to get a "
         "shutdown dialog from there. If you want a direct shutdown, then "
         "please consider going into the preferences and setting the shutdown "
         "method to ConsoleKit or something else.\n\nPlease feel free to visit "
         "https://launchpad.net/~hakaishi to report bugs or for anyting "
         "concerning translations."));
       infoBox->setStandardButtons(QMessageBox::Ok);
     }
}

void Preferences::showEvent(QShowEvent* show_pref){
     if(!settings->isWritable())
     {
       QTimer::singleShot(15000, msgBox, SLOT(close()));
       msgBox->show();
     }
     loadSettings();
     QDialog::showEvent(show_pref);
}

void Preferences::loadSettings(){
     if(settings->value("first_start", true).toBool())
     {
       infoBox->show();
       settings->setValue("first_start", false);
     }

     if(!settings->contains("shutdown_method"))
       settings->setValue("shutdown_method", 0);
     if(!settings->contains("CheckBoxes/atDate"))
       settings->setValue("CheckBoxes/atDate", false);
     if(!settings->contains("CheckBoxes/logging"))
       settings->setValue("CheckBoxes/logging", false);
     if(!settings->contains("CheckBoxes/shutdown"))
       settings->setValue("CheckBoxes/shutdown", false);
     if(!settings->contains("CheckBoxes/quitWithLastProcess"))
       settings->setValue("CheckBoxes/quitWithLastProcess", false);
     if(!settings->contains("Text/text1"))
       settings->setValue("Text/text1", QString());
     if(!settings->contains("Text/text2"))
       settings->setValue("Text/text2", QString());

//read settings
     comboBox->setCurrentIndex(settings->value("shutdown_method", 0).toInt());
}

void Preferences::saveToConfFile(){
     settings->setValue("shutdown_method",comboBox->currentIndex());
}