Save the mainwindow state properly when exiting the client.
[quassel.git] / src / uisupport / settingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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) version 3.                                           *
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 #ifndef _SETTINGSPAGE_H_
22 #define _SETTINGSPAGE_H_
23
24 #include <QWidget>
25
26 //! A SettingsPage is a page in the settings dialog.
27 /** The SettingsDlg provides suitable standard buttons, such as Ok, Apply, Cancel, Restore Defaults and Reset.
28  *  Some pages might also be used in standalone dialogs or other containers. A SettingsPage provides suitable
29  *  slots and signals to allow interaction with the container.
30  */
31 class SettingsPage : public QWidget {
32   Q_OBJECT
33
34   public:
35     SettingsPage(const QString &category, const QString &name, QWidget *parent = 0);
36     virtual ~SettingsPage() {};
37
38     //! The category of this settings page.
39     virtual QString category() const;
40
41     //! The title of this settings page.
42     virtual QString title() const;
43
44     //! Derived classes need to define this and return true if they have default settings.
45     /** If this method returns true, the "Restore Defaults" button in the SettingsDlg is
46      *  enabled. You also need to provide an implementation of defaults() then.
47      *
48      * The default implementation returns false.
49      */
50     virtual bool hasDefaults() const;
51
52     //! Check if there are changes in the page, compared to the state saved in permanent storage.
53     bool hasChanged() const;
54
55     //! Called immediately before save() is called.
56     /** Derived classes should return false if saving is not possible (e.g. the current settings are invalid).
57      *  \return false, if the SettingsPage cannot be saved in its current state.
58      */
59     virtual bool aboutToSave();
60
61   public slots:
62     //! Save settings to permanent storage.
63     virtual void save() = 0;
64
65     //! Load settings from permanent storage, overriding any changes the user might have made in the dialog.
66     virtual void load() = 0;
67
68     //! Restore defaults, overriding any changes the user might have made in the dialog.
69     /** The default implementation does nothing.
70      */
71     virtual void defaults();
72
73   protected slots:
74     //! Calling this slot is equivalent to calling setChangedState(true).
75     void changed();
76
77   protected:
78     //! This should be called whenever the widget state changes from unchanged to change or the other way round.
79     void setChangedState(bool hasChanged = true);
80
81   signals:
82     //! Emitted whenever the widget state changes.
83     void changed(bool hasChanged);
84
85   private:
86     QString _category, _title;
87     bool _changed;
88 };
89
90 #endif