File: config.cpp

package info (click to toggle)
arqiver 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 768 kB
  • sloc: cpp: 3,563; makefile: 6
file content (106 lines) | stat: -rw-r--r-- 2,979 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
/*
 * Copyright (C) Pedram Pourang (aka Tsu Jan) 2018 <tsujan2000@gmail.com>
 *
 * Arqiver 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.
 *
 * Arqiver 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/>.
 *
 * @license GPL-3.0+ <https://spdx.org/licenses/GPL-3.0+.html>
 */

#include "config.h"

namespace Arqiver {

Config::Config() :
  remSize_(true),
  isMaxed_(false),
  removalPrompt_(true),
  stretchFirstColumn_(false),
  expandTopDirs_(false),
  winSize_(QSize(700, 500)),
  startSize_(QSize(700, 500)),
  iconSize_(24) {
}

Config::~Config() {}

void Config::readConfig() {
  Settings settings("arqiver", "arq");

  settings.beginGroup("window");

  if (settings.value("size") == "none")
    remSize_ = false; // true by default
  else {
    winSize_ = settings.value("size", QSize(700, 500)).toSize();
    if (!winSize_.isValid() || winSize_.isNull())
      winSize_ = QSize(700, 500);
    isMaxed_ = settings.value("max", false).toBool();
  }
  startSize_ = settings.value("startSize", QSize(700, 500)).toSize();
  if (!startSize_.isValid() || startSize_.isNull())
    startSize_ = QSize(700, 500);

  iconSize_ = qMin(qMax(settings.value("iconSize", 24).toInt(), 22), 64);

  removalPrompt_ = settings.value("removalPrompt", true).toBool();

  stretchFirstColumn_ = settings.value("stretchFirstColumn", false).toBool();

  expandTopDirs_ = settings.value("expandTopDirs", false).toBool();

  settings.endGroup();

  settings.beginGroup("archive");
  lastFilter_ = settings.value("lastFilter").toString();
  tarBinary_ = settings.value("tarBinary").toString();
  settings.endGroup();
}
/*************************/
void Config::writeConfig() {
  Settings settings("arqiver", "arq");
  if (!settings.isWritable()) return;

  settings.beginGroup("window");

  if (remSize_) {
    settings.setValue("size", winSize_);
    settings.setValue("max", isMaxed_);
  }
  else {
    settings.setValue("size", "none");
    settings.remove("max");
  }

  settings.setValue("startSize", startSize_);

  settings.setValue("iconSize", iconSize_);

  settings.setValue("removalPrompt", removalPrompt_);

  settings.setValue("stretchFirstColumn", stretchFirstColumn_);

  settings.setValue("expandTopDirs", expandTopDirs_);

  settings.endGroup();

  settings.beginGroup("archive");
  settings.setValue("lastFilter", lastFilter_);
  if (tarBinary_.isEmpty())
    settings.remove("tarBinary");
  else
    settings.setValue("tarBinary", tarBinary_);
  settings.endGroup();
}

}