chatlogscfg.cpp
1 //------------------------------------------------------------------------------
2 // chatlogscfg.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "chatlogscfg.h"
24 
25 #include "datapaths.h"
26 #include "irc/configuration/ircconfig.h"
27 
28 DClass<ChatLogsCfg>
29 {
30 };
31 
32 DPointered(ChatLogsCfg)
33 
34 
36 {
37 }
38 
39 ChatLogsCfg::~ChatLogsCfg()
40 {
41 }
42 
43 QString ChatLogsCfg::chatLogsRootDir() const
44 {
45  return value("ChatLogsRootDir", gDefaultDataPaths->localDataLocationPath(
46  DataPaths::CHATLOGS_DIR_NAME)).toString();
47 }
48 
49 void ChatLogsCfg::setChatLogsRootDir(const QString &val)
50 {
51  setValue("ChatLogsRootDir", val);
52 }
53 
54 bool ChatLogsCfg::isStoreLogs() const
55 {
56  return value("StoreLogs", true).toBool();
57 }
58 
59 void ChatLogsCfg::setStoreLogs(bool b)
60 {
61  setValue("StoreLogs", b);
62 }
63 
64 bool ChatLogsCfg::isRestoreChatFromLogs() const
65 {
66  return value("RestoreChatFromLogs", true).toBool();
67 }
68 
69 void ChatLogsCfg::setRestoreChatFromLogs(bool b)
70 {
71  setValue("RestoreChatFromLogs", b);
72 }
73 
74 bool ChatLogsCfg::isRemoveOldLogs() const
75 {
76  return value("RemoveOldLogs", false).toBool();
77 }
78 void ChatLogsCfg::setRemoveOldLogs(bool b)
79 {
80  setValue("RemoveOldLogs", b);
81 }
82 
83 int ChatLogsCfg::oldLogsRemovalDaysThreshold() const
84 {
85  int val = value("OldLogsRemovalDaysThreshold", 365).toInt();
86  return qMax(1, val);
87 }
88 
89 void ChatLogsCfg::setOldLogsRemovalDaysThreshold(int val)
90 {
91  setValue("OldlogsRemovalDaysThreshold", val);
92 }
93 
94 void ChatLogsCfg::setValue(const QString &key, const QVariant &value)
95 {
96  gIRCConfig.ini()->section("Logs").setValue(key, value);
97 }
98 
99 QVariant ChatLogsCfg::value(const QString &key, const QVariant &defValue) const
100 {
101  return gIRCConfig.ini()->section("Logs").value(key, defValue);
102 }