81ef6090d9ea6c0542140e7c9553939da5baf4ab
[quassel.git] / src / qtui / settingspages / backlogsettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (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                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "backlogsettingspage.h"
22
23 #include "qtui.h"
24 #include "backlogsettings.h"
25
26 BacklogSettingsPage::BacklogSettingsPage(QWidget *parent)
27   : SettingsPage(tr("Behaviour"), tr("Backlog"), parent)
28 {
29   ui.setupUi(this);
30   connect(ui.requesterType, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
31
32   connect(ui.fixedBacklogAmount, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
33   connect(ui.globalUnreadLimit, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
34   connect(ui.globalUnreadAdditional, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
35   connect(ui.perBufferUnreadLimit, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
36   connect(ui.perBufferUnreadAdditional, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
37
38   connect(ui.dynamicBacklogAmount, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
39 }
40
41 bool BacklogSettingsPage::hasDefaults() const {
42   return true;
43 }
44
45 void BacklogSettingsPage::defaults() {
46   //  ui.completionSuffix->setText(": ");
47
48   widgetHasChanged();
49 }
50
51 void BacklogSettingsPage::load() {
52   BacklogSettings backlogSettings;
53   SettingsPage::load(ui.requesterType, backlogSettings.requesterType() - 1);
54   
55   SettingsPage::load(ui.fixedBacklogAmount, backlogSettings.fixedBacklogAmount());
56   SettingsPage::load(ui.globalUnreadLimit, backlogSettings.globalUnreadBacklogLimit());
57   SettingsPage::load(ui.globalUnreadAdditional, backlogSettings.globalUnreadBacklogAdditional());
58   SettingsPage::load(ui.perBufferUnreadLimit, backlogSettings.perBufferUnreadBacklogLimit());
59   SettingsPage::load(ui.perBufferUnreadAdditional, backlogSettings.perBufferUnreadBacklogAdditional());
60   
61   SettingsPage::load(ui.dynamicBacklogAmount, backlogSettings.dynamicBacklogAmount());
62
63   setChangedState(false);
64 }
65
66 void BacklogSettingsPage::save() {
67   BacklogSettings backlogSettings;
68   backlogSettings.setRequesterType(ui.requesterType->currentIndex() + 1);
69   backlogSettings.setFixedBacklogAmount(ui.fixedBacklogAmount->value());
70   backlogSettings.setGlobalUnreadBacklogLimit(ui.globalUnreadLimit->value());
71   backlogSettings.setGlobalUnreadBacklogAdditional(ui.globalUnreadAdditional->value());
72   backlogSettings.setPerBufferUnreadBacklogLimit(ui.perBufferUnreadLimit->value());
73   backlogSettings.setPerBufferUnreadBacklogAdditional(ui.perBufferUnreadAdditional->value());
74   
75   backlogSettings.setDynamicBacklogAmount(ui.dynamicBacklogAmount->value());
76
77   load();
78   setChangedState(false);
79 }
80
81 void BacklogSettingsPage::widgetHasChanged() {
82   bool changed = testHasChanged();
83   if(changed != hasChanged()) setChangedState(changed);
84 }
85
86 bool BacklogSettingsPage::testHasChanged() {
87   if(SettingsPage::hasChanged(ui.fixedBacklogAmount)) return true;
88   if(SettingsPage::hasChanged(ui.dynamicBacklogAmount)) return true;
89
90   return false;
91 }