cfgchatlogspage.cpp
1 //------------------------------------------------------------------------------
2 // cfgchatlogspage.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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 "cfgchatlogspage.h"
24 #include "ui_cfgchatlogspage.h"
25 
26 #include "irc/configuration/chatlogscfg.h"
27 #include <QDesktopServices>
28 #include <QFileDialog>
29 #include <QFileInfo>
30 #include <QMessageBox>
31 #include <QUrl>
32 
33 DClass<CfgChatLogsPage> : public Ui::CfgChatLogsPage
34 {
35 };
36 
37 DPointered(CfgChatLogsPage)
38 
39 
40 CfgChatLogsPage::CfgChatLogsPage(QWidget *parent)
41 : ConfigurationBaseBox(parent)
42 {
43  d->setupUi(this);
44 }
45 
46 CfgChatLogsPage::~CfgChatLogsPage()
47 {
48 }
49 
50 void CfgChatLogsPage::browseStorageDirectory()
51 {
52  QString path = QFileDialog::getExistingDirectory(this,
53  tr("Browse chat logs storage directory"), d->leDir->text());
54  if (!path.isEmpty())
55  {
56  d->leDir->setText(path);
57  }
58 }
59 
60 bool CfgChatLogsPage::checkDir(const QString &directory)
61 {
62  if (directory.trimmed().isEmpty())
63  {
64  QMessageBox::critical(this, tr("Directory error"), tr("Directory not specified."));
65  return false;
66  }
67 
68  QFileInfo dir(directory);
69  if (!dir.exists())
70  {
71  QMessageBox::critical(this, tr("Directory error"), tr("Directory doesn't exist."));
72  return false;
73  }
74  if (!dir.isDir())
75  {
76  QMessageBox::critical(this, tr("Directory error"), tr("Specified path isn't a directory."));
77  return false;
78  }
79  return true;
80 }
81 
82 void CfgChatLogsPage::exploreStorageDirectory()
83 {
84  if (checkDir(d->leDir->text()))
85  {
86  QString path = QDir::toNativeSeparators(d->leDir->text());
87  QDesktopServices::openUrl(QString("file:///%1").arg(path));
88  }
89 }
90 
92 {
93  ChatLogsCfg cfg;
94  d->leDir->setText(cfg.chatLogsRootDir());
95  d->cbStoreLogs->setChecked(cfg.isStoreLogs());
96  d->cbRestoreLogs->setChecked(cfg.isRestoreChatFromLogs());
97  d->groupRemoveOldArchives->setChecked(cfg.isRemoveOldLogs());
98  d->spinLogRemovalAge->setValue(cfg.oldLogsRemovalDaysThreshold());
99 }
100 
102 {
103  ChatLogsCfg cfg;
104  cfg.setChatLogsRootDir(d->leDir->text());
105  cfg.setStoreLogs(d->cbStoreLogs->isChecked());
106  cfg.setRestoreChatFromLogs(d->cbRestoreLogs->isChecked());
107  cfg.setRemoveOldLogs(d->groupRemoveOldArchives->isChecked());
108  cfg.setOldLogsRemovalDaysThreshold(d->spinLogRemovalAge->value());
109 }
void readSettings()
Reimplement this to read settings from config into widgets.
void saveSettings()
Reimplement this to write settings to config from widgets.
Base class for configuration pages.