File: gui.cpp

package info (click to toggle)
shutdown-qapps 1.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,640 kB
  • sloc: cpp: 3,967; makefile: 10; sh: 1
file content (547 lines) | stat: -rw-r--r-- 22,222 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/* 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 "gui.h"
#include "preferences.h"
#include <QMessageBox>
#include <QSettings>
#include <QFile>

#ifndef Q_OS_WIN32
  #include <QtDBus>
#endif

Gui::Gui(){

     setupUi(this);

     pref = new Preferences(this);

     myOutput = new QTextStream(stdout);

     if(!QProcessEnvironment().isEmpty())
        shell = QProcess::systemEnvironment().filter("SHELL").first().remove("SHELL=");
     if(shell.isEmpty() && QFile("/bin/bash").exists())
        shell = "/bin/bash";
     else
       *myOutput << "E: No shells found! qprogram-starter might not work as expected...";

   //Versioning
     QFile versionFile(":version");
     versionFile.open(QIODevice::ReadOnly | QIODevice::Text);
     QTextStream in(&versionFile);
     statusBar()->showMessage(tr("Version ") + in.readLine(),15000);
     versionFile.close();

     aborted = false;
     process2Started = false;

     dateEdit->setMinimumDate(QDate::currentDate());
     dateTimeTimer = new QTimer(this);
     dateTimeTimer->start(1000);

     timer = new QTimer(this);

     process1 = new QProcess(this);
     process2 = new QProcess(this);

     logBox1 = new QTextEdit;
     logBox1->setReadOnly(true);
     logBox1->resize(520,450);
     logBox1->setWindowTitle("error log 1");
     logBox1->setWindowModality(Qt::NonModal);

     logBox2 = new QTextEdit;
     logBox2->setReadOnly(true);
     logBox2->resize(520,450);
     logBox2->setWindowTitle("error log 2");
     logBox2->setWindowModality(Qt::NonModal);

     hintMsgBox = new QTextEdit;
     hintMsgBox->setReadOnly(true);
     hintMsgBox->resize(520,450);
     hintMsgBox->setWindowTitle("Info");
     hintMsgBox->setWindowModality(Qt::NonModal);
     hintMsgBox->setHtml(tr("The command in the second text editor (if there is any) will be executed after the first one. The message boxes will close themselves after 10 seconds.<br/>To start a program just type i.e. \"firefox\" or \"firefox www.google.com\" and then click on Start. Commands etc. can be linked by \"&&\" etc. <br/><br/>If the process is \"finished\" although it is still running, then try the --nofork option (i.e. kopete --nofork). Note that this will also occure for some programs like gedit, firefox or gnome-terminal if they are already running.<br/><br/>When you want to start a program or command with sudo, please use for example gksu(do) or kdesu(do).<br/><br/>make examples:<br/>&nbsp;make -C /path/to/project<br/>&nbsp;make clean -C /path/to/project<br/><br/>About Errors:<br/>Because almost every program gives a different error code, it is impossible to say what happend. So just log the output and see what kind of error occured. The output files can be found at <i>~/.qprogram-starter/</i>.<br/><br/>If the shutdown won't work, it means that \"sudo shutdown -P now\" is used. This needs root permissions. You can do the this:<br/><br/>Post the following in a terminal:<pre>EDITOR=nano sudo -E visudo</pre> and add this line:<pre>* ALL = NOPASSWD:/sbin/shutdown</pre> whereas * replaces the username or %groupname.<br/><br/>The configuration-file can be found at <i>~/.qprogram-starter/</i>."));

     connect(action_Configure, SIGNAL(triggered(bool)), pref, SLOT(show()));
     connect(dateTimeTimer, SIGNAL(timeout()), this, SLOT(currentDateAndTime()));
     connect(startB, SIGNAL(clicked(bool)), this, SLOT(run()));
     connect(abortB, SIGNAL(clicked(bool)), this, SLOT(abortProcesses()));
     connect(saveButton, SIGNAL(clicked(bool)), this, SLOT(saveData()));
     connect(timer, SIGNAL(timeout()), this, SLOT(check()));
     connect(browse1, SIGNAL(clicked(bool)), this, SLOT(getProgram1()));
     connect(browse2, SIGNAL(clicked(bool)), this, SLOT(getProgram2()));
     connect(process1, SIGNAL(readyReadStandardOutput()), this, SLOT(output1()));
     connect(process1, SIGNAL(readyReadStandardError()), this, SLOT(errorOutput1()));
     connect(process1, SIGNAL(finished(int)), this, SLOT(checkForProcess2()));
     connect(process1, SIGNAL(error(QProcess::ProcessError)), this, SLOT(message()));
     connect(process2, SIGNAL(readyReadStandardOutput()), this, SLOT(output2()));
     connect(process2, SIGNAL(readyReadStandardError()), this, SLOT(errorOutput2()));
     connect(process2, SIGNAL(finished(int)), this, SLOT(shutdown_or_message()));
     connect(process2, SIGNAL(error(QProcess::ProcessError)), this, SLOT(message()));
     connect(this, SIGNAL(finished()), this, SLOT(shutdown_or_message()));
     connect(action_Hints, SIGNAL(triggered(bool)), this, SLOT(info_hint()));
     connect(showLogsButton, SIGNAL(clicked(bool)), this, SLOT(showLogs()));
}

Gui::~Gui(){ delete hintMsgBox; }

void Gui::closeEvent(QCloseEvent* window_close){
     if(!pref->settings->isWritable())
       *myOutput << "W: qprogram-starter.conf is not writable!" << endl;
     else
       saveSettings();
     //qApp->quit();
     QMainWindow::closeEvent(window_close);
}

void Gui::currentDateAndTime(){
     if(dateEdit->date() == QDate::currentDate())
       timeEdit->setMinimumTime(QTime::currentTime());
     else
       timeEdit->setMinimumTime(QTime(00,00));
}

void Gui::info_hint(){ hintMsgBox->show(); }

void Gui::check(){ //To check if start time is reached
     secondsToTimeInTheFuture = QDateTime::currentDateTime().secsTo(timeInTheFuture);
     if(secondsToTimeInTheFuture <= 0){
       processArgs1 << "-c" << plainTextEdit->toPlainText();
       process1->start(shell, processArgs1);
       timer->stop();
     }
}

void Gui::getProgram1(){
     program1 = QFileDialog::getOpenFileName(this, tr("Select a program"), "/usr/bin");
     plainTextEdit->insertPlainText(program1);
     plainTextEdit->setFocus();
}

void Gui::getProgram2(){
     program2 = QFileDialog::getOpenFileName(this, tr("Select a program"), "/usr/bin");
     plainTextEdit2->insertPlainText(program2);
     plainTextEdit2->setFocus();
}

void Gui::run(){ //To start either the timer or start the process
     if(!plainTextEdit->toPlainText().isEmpty()){
       nextDate = dateEdit->dateTime();
       timeInTheFuture = nextDate.addSecs(timeEdit->time().hour()*3600 + timeEdit->time().minute()*60 + timeEdit->time().second());
       plainTextEdit->setDisabled(true);
       atDateCheckBox->setDisabled(true);
       dateEdit->setDisabled(true);
       timeEdit->setDisabled(true);
       if(atDateCheckBox->isChecked())
         timer->start(1000);
       else{
         processArgs1 << "-c" << plainTextEdit->toPlainText();
         process1->start(shell, processArgs1);
       }
     }
     else{
       QMessageBox msgBox;
       msgBox.setWindowTitle("Error");
       msgBox.setIcon(QMessageBox::Warning);
       msgBox.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Window);
       msgBox.setInformativeText(tr("The first text edit is empty!"));
       QTimer::singleShot(6000, &msgBox, SLOT(close()));
       msgBox.exec();
     }
     outputProcess1 = "";
     outputProcess2 = "";
     errProcess1 = "";
     errProcess2 = "";
}

void Gui::abortProcesses(){
     timer->stop();
     aborted = true;

     process1->close();
     process2->close();

     processArgs1.clear();
     processArgs2.clear();

     QMessageBox msgBox;
     msgBox.setWindowTitle(tr("Information"));
     msgBox.setIcon(QMessageBox::Information);
     msgBox.setInformativeText(tr("Processes aborted"));
     msgBox.setWindowModality(Qt::NonModal);
     msgBox.setWindowFlags(Qt::WindowStaysOnTopHint);
     QTimer::singleShot(10000, &msgBox, SLOT(close()));
     msgBox.exec();

     atDateCheckBox->setEnabled(true);
     if(atDateCheckBox->isChecked()){
       dateEdit->setEnabled(true);
       timeEdit->setEnabled(true);
     }
     plainTextEdit->setEnabled(true);
     plainTextEdit2->setEnabled(true);

     aborted = false;
}

void Gui::checkForProcess2(){ //check if there is a second command
     if(process1->exitCode()==0 && process1->exitStatus()==0 && process1->error()==5
       && !plainTextEdit2->toPlainText().isEmpty() && !aborted){
       processArgs2 << "-c" << plainTextEdit2->toPlainText();
       process2->start(shell, processArgs2);
       process2Started = true;
       plainTextEdit2->setDisabled(true);
     }
     else
       finished();
}

void Gui::output1(){ //write output into a file if loggingCheckBox is checked
     QString string = QString::fromLocal8Bit(process1->readAllStandardOutput());
     outputProcess1 += string;

     if(loggingCheckBox->isChecked()){
       QFile outputLog1(QDir::homePath() + "/.qprogram-starter/outputLog1.txt");
       if(!outputLog1.open(QIODevice::Append))
         return;
       QTextStream str(&outputLog1);
       str << string;
       outputLog1.close();
     }
}

void Gui::output2(){ //write output into a file if loggingCheckBox is checked
     QString string = QString::fromLocal8Bit(process2->readAllStandardOutput());
     outputProcess2 += string;

     if(loggingCheckBox->isChecked()){
       QFile outputLog2(QDir::homePath() + "/.qprogram-starter/outputLog2.txt");
       if(!outputLog2.open(QIODevice::Append))
         return;
       QTextStream str(&outputLog2);
       str << string;
       outputLog2.close();
     }
}

void Gui::errorOutput1(){ //write error output into a file if loggingCheckBox is checked
     QString string = QString::fromLocal8Bit(process1->readAllStandardError());
     errProcess1 += string;

     if(loggingCheckBox->isChecked()){
       QFile errorLog1(QDir::homePath() + "/.qprogram-starter/errorLog1.txt");
       if(!errorLog1.open(QIODevice::Append))
         return;
       QTextStream str(&errorLog1);
       str << string;
       errorLog1.close();
     }
}

void Gui::errorOutput2(){ //write error output into a file if loggingCheckBox is checked
     QString string = QString::fromLocal8Bit(process2->readAllStandardError());
     errProcess2 += string;

     if(loggingCheckBox->isChecked()){
       QFile errorLog2(QDir::homePath() + "/.qprogram-starter/errorLog2.txt");
       if(!errorLog2.open(QIODevice::Append))
         return;
       QTextStream str(&errorLog2);
       str << string;
       errorLog2.close();
     }
}

void Gui::showLogs(){
     if(!outputProcess1.isEmpty() || !errProcess1.isEmpty()
       || !outputProcess2.isEmpty() || !errProcess2.isEmpty()){
       if(!outputProcess1.isEmpty())
         logBox1->append(outputProcess1);
       if(!errProcess1.isEmpty())
         logBox1->append(errProcess1);
       logBox1->show();

       if(process1->exitCode()==0 && process1->exitStatus()==0
         && process1->error()==5 && !plainTextEdit2->toPlainText().isEmpty() && !aborted){
         if(!outputProcess2.isEmpty())
           logBox2->append(outputProcess2);
         if(!errProcess2.isEmpty())
           logBox2->append(errProcess2);
         logBox2->show();
       }
     }
}     

void Gui::shutdown_or_message(){
     if(!shutdownCheckBox->isChecked() || aborted)
     {
        message();
        return;
     }
     else
     {

       saveSettings();

      #ifndef Q_OS_WIN32
       bool l = false;
       bool g = false; //gnome
       bool k = false; //kde
       bool g_pwr1 = false;
       bool g_pwr2 = false;
       bool hal = false;

       QDBusMessage response;

       QDBusInterface freedesktopLogin1("org.freedesktop.login1",
        "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
        QDBusConnection::systemBus());
       QDBusInterface gnomeSessionManager("org.gnome.SessionManager",
        "/org/gnome/SessionManager", "org.gnome.SessionManager",
        QDBusConnection::sessionBus());
       QDBusInterface kdeSessionManager("org.kde.ksmserver", "/KSMServer",
        "org.kde.KSMServerInterface", QDBusConnection::sessionBus());
       QDBusInterface freedesktopHal("org.freedesktop.Hal",
        "/org/freedesktop/Hal/devices/computer",
        "org.freedesktop.Hal.Device.SystemPowerManagement",
        QDBusConnection::systemBus());
       QDBusInterface freedesktopConsoleKit("org.freedesktop.ConsoleKit",
        "/org/freedesktop/ConsoleKit/Manager",
        "org.freedesktop.ConsoleKit.Manager",
        QDBusConnection::systemBus());
      #else
       QProcess::startDetached("shutdown -r -f -t 00"); // Windows command to reboot immediately
       }
      #endif

       if(pref->comboBox->currentIndex() == 0){ //automatic
         if(QProcess::startDetached("/usr/bin/systemctl poweroff"))
           return;
         g_pwr1 = QProcess::startDetached("gnome-power-cmd.sh shutdown");
         g_pwr2 = QProcess::startDetached("gnome-power-cmd shutdown");
         if(!g_pwr1 && !g_pwr2){
           *myOutput << "W: gnome-power-cmd and gnome-power-cmd.sh didn't work"
                     << endl;
           response = gnomeSessionManager.call("RequestShutdown");
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
           else g = true;
           if(!g){
             response = gnomeSessionManager.call("Shutdown");
             if(response.type() == QDBusMessage::ErrorMessage)
               *myOutput << "W: " << response.errorName() << ": "
                         << response.errorMessage() << endl;
             else g = true;
           }
         }
         else g = true;

         if(!g){
         response = freedesktopLogin1.call("PowerOff", true);
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
           else l = true;
         }

         if(!g &&!l){
           response = kdeSessionManager.call("logout", 0, 2, 2);
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
           else k = true;
         }

         if(!g && !l && !k){
           response = freedesktopHal.call("Shutdown");
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
           else hal = true;
         }

         if(!g && !l && !k && !hal){
           response = freedesktopConsoleKit.call("Stop");
           if(response.type() == QDBusMessage::ErrorMessage){
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
             QProcess::startDetached("sudo shutdown -P now");
           }
         }
       } //end of automatic

       if(pref->comboBox->currentIndex() == 1){
         response = freedesktopLogin1.call("PowerOff", true);
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                       << response.errorMessage() << endl;
       }

       if(pref->comboBox->currentIndex() == 2){ //gnome
         g_pwr1 = QProcess::startDetached("gnome-power-cmd.sh shutdown");
         g_pwr2 = QProcess::startDetached("gnome-power-cmd shutdown");
         if(!g_pwr1 && !g_pwr2){
           *myOutput << "W: gnome-power-cmd and gnome-power-cmd.sh didn't work"
                     << endl;
           response = gnomeSessionManager.call("RequestShutdown");
           if(response.type() == QDBusMessage::ErrorMessage)
             *myOutput << "W: " << response.errorName() << ": "
                     << response.errorMessage() << endl;
           else g = true;
           if(!g){
             response = gnomeSessionManager.call("Shutdown");
             if(response.type() == QDBusMessage::ErrorMessage)
               *myOutput << "W: " << response.errorName() << ": "
                         << response.errorMessage() << endl;
           }
         }
       }

       if(pref->comboBox->currentIndex() == 3){ //kde
         response = kdeSessionManager.call("logout", 0, 2, 2);
         if(response.type() == QDBusMessage::ErrorMessage)
           *myOutput << "W: " << response.errorName() << ": "
                     << response.errorMessage() << endl;
       }

       if(pref->comboBox->currentIndex() == 4){ //hal
         response = freedesktopHal.call("Shutdown");
         if(response.type() == QDBusMessage::ErrorMessage)
           *myOutput << "W: " << response.errorName() << ": "
                     << response.errorMessage() << endl;
       }

       if(pref->comboBox->currentIndex() == 5){ //consoleKit
         response = freedesktopConsoleKit.call("Stop");
         if(response.type() == QDBusMessage::ErrorMessage)
           *myOutput << "W: " << response.errorName() << ": "
                     << response.errorMessage() << endl;
       }

       if(pref->comboBox->currentIndex() == 6){ //sudo
         if(QProcess::startDetached("sudo /usr/bin/systemctl poweroff"))
           return;
         QProcess::startDetached("sudo shutdown -P now");
         QProcess::startDetached("sudo shutdown -h -P now");
       }
     }

     processArgs1.clear();
     processArgs2.clear();
     qApp->quit(); //otherwise some systems might prompt to quit the program
}

void Gui::message(){
     if(!aborted){
       QMessageBox msgBox;
       if(process1->exitCode()==0 && process1->exitStatus()==0 && process1->error()==5){
         if(plainTextEdit2->toPlainText().isEmpty()){
           msgBox.setWindowTitle(tr("Information"));
           msgBox.setIcon(QMessageBox::Information);
           msgBox.setInformativeText(tr("<b>process 1 finished!</b>"));
         }
       }
       if(process2Started && process2->exitCode()==0 && process2->exitStatus()==0 && process2->error()==5){
         msgBox.setWindowTitle(tr("Information"));
         msgBox.setIcon(QMessageBox::Information);
         msgBox.setInformativeText(tr("<b>process 1 & 2 finished!</b>"));
       }

       if((process1->exitCode()!=0 || process1->error()!=5) ||
          (process2->exitCode()!=0 || process2->error()!=5)){
         msgBox.setWindowTitle(tr("Error"));
         msgBox.setIcon(QMessageBox::Critical);
         if(process1->error()==0 || process2->error()==0){
           msgBox.setInformativeText(tr("<b>Failed to start!</b><br/>"
            "No such program or command."));
           if(loggingCheckBox->isChecked()){
             if(process1->error()==0){
               QFile errorLog1(QDir::homePath() + "/.qprogram-starter/errorLog1.txt");
               if(!errorLog1.open(QIODevice::Append))
                 return;
               QTextStream err1(&errorLog1);
               err1 << tr("\"%1\": Failed to start! No such program or "
                          "command.\n").arg(plainTextEdit->toPlainText());
               errorLog1.close();
             }

             if(process2->error()==0){
               QFile errorLog2(QDir::homePath() + "/.qprogram-starter/errorLog2.txt");
               if(!errorLog2.open(QIODevice::Append))
                 return;
               QTextStream err2(&errorLog2);
               err2 << tr("\"%1\": Failed to start! No such program or "
                          "command.\n").arg(plainTextEdit2->toPlainText());
               errorLog2.close();
             }
           }
         }
         else if(process1->error()==1 || process1->exitCode()==1)
           msgBox.setInformativeText(tr("<b>process 1 crashed!</b><br/>"
           "This could be caused by invalid parameters or options."));
         else if(process2->error()==1 || process2->exitCode()==1)
           msgBox.setInformativeText(tr("<b>process 2 crashed!</b><br/>"
           "This could be caused by invalid parameters or options."));
         else
           msgBox.setInformativeText(tr("<b>Unknown error!</b><br/>"
           "This could be caused by invalid parameters or options."));
       }
       msgBox.setWindowModality(Qt::NonModal);
       msgBox.setWindowFlags(Qt::WindowStaysOnTopHint);
       QTimer::singleShot(10000, &msgBox, SLOT(close()));
       msgBox.exec();
     }

     atDateCheckBox->setEnabled(true);
     if(atDateCheckBox->isChecked()){
       dateEdit->setEnabled(true);
       timeEdit->setEnabled(true);
     }
     plainTextEdit->setEnabled(true);
     plainTextEdit2->setEnabled(true);

     if(quitCheckBox->isChecked() && !aborted)
       close();

     processArgs1.clear();
     processArgs2.clear();
}

void Gui::saveData(){
     pref->settings->setValue("Text/text1", plainTextEdit->toPlainText());
     pref->settings->setValue("Text/text2", plainTextEdit2->toPlainText());
}

void Gui::saveSettings(){
     pref->settings->setValue("CheckBoxes/atDate", atDateCheckBox->isChecked());
     pref->settings->setValue("CheckBoxes/logging", loggingCheckBox->isChecked());
     pref->settings->setValue("CheckBoxes/shutdown", shutdownCheckBox->isChecked());
     pref->settings->setValue("CheckBoxes/quitWithLastProcess", quitCheckBox->isChecked());
}

void Gui::loadSettings(){
     atDateCheckBox->setChecked(pref->settings->value("CheckBoxes/atDate").toBool());
     loggingCheckBox->setChecked(pref->settings->value("CheckBoxes/logging").toBool());
     shutdownCheckBox->setChecked(pref->settings->value("CheckBoxes/shutdown").toBool());
     quitCheckBox->setChecked(pref->settings->value("CheckBoxes/quitWithLastProcess").toBool());
     plainTextEdit->setPlainText(pref->settings->value("Text/text1").toString());
     plainTextEdit2->setPlainText(pref->settings->value("Text/text2").toString());
}