1 /****************************************************************************
2     Copyright (C) 2001-2009 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #ifndef TELLICO_CONFIGDIALOG_H
26 #define TELLICO_CONFIGDIALOG_H
27 
28 #include "fetch/fetcherinfolistitem.h"
29 
30 #include <KPageDialog>
31 
32 #include <QListWidget>
33 
34 class KConfig;
35 class KIntNumInput;
36 class KColorCombo;
37 
38 class QSpinBox;
39 class QPushButton;
40 class QLineEdit;
41 class QFontComboBox;
42 class QCheckBox;
43 class QRadioButton;
44 class QFrame;
45 
46 namespace Tellico {
47   namespace Fetch {
48     class ConfigWidget;
49   }
50   namespace GUI {
51     class ComboBox;
52     class CollectionTypeCombo;
53   }
54 
55 /**
56  * The configuration dialog class allows the user to change the global application
57  * preferences.
58  *
59  * @author Robby Stephenson
60  */
61 class ConfigDialog : public KPageDialog {
62 Q_OBJECT
63 
64 public:
65   /**
66    * The constructor sets up the Tabbed dialog pages.
67    *
68    * @param parent A pointer to the parent widget
69    */
70   ConfigDialog(QWidget* parent);
71   virtual ~ConfigDialog();
72 
73   /**
74    * Saves the configuration
75    */
76   void saveConfiguration();
77 
78 Q_SIGNALS:
79   /**
80    * Emitted whenever the Ok or Apply button is clicked.
81    */
82   void signalConfigChanged();
83 
84 private Q_SLOTS:
85   /**
86    * Called when anything gets changed
87    */
88   void slotModified();
89   /**
90    * Called when the Ok button is clicked.
91    */
92   virtual void accept() Q_DECL_OVERRIDE;
93   /**
94    * Called when the Apply button is clicked.
95    */
96   void slotApply();
97   /**
98    * Called when the Default button is clicked.
99    */
100   void slotDefault();
101   void slotHelp();
102   void slotInitPage(KPageWidgetItem* item);
103   /**
104    * Create a new Internet source
105    */
106   void slotNewSourceClicked();
107   /**
108    * Modify a Internet source
109    */
110   void slotModifySourceClicked();
111   /**
112    * Remove a Internet source
113    */
114   void slotRemoveSourceClicked();
115   void slotSelectedSourceChanged(QListWidgetItem* item);
116   void slotMoveUpSourceClicked();
117   void slotMoveDownSourceClicked();
118   void slotSourceFilterChanged();
119   void slotNewStuffClicked();
120   void slotShowTemplatePreview();
121   void slotInstallTemplate();
122   void slotDownloadTemplate();
123   void slotDeleteTemplate();
124   void slotCreateConfigWidgets();
125 
126 private:
127   enum Page {
128     General  = 1 << 0,
129     Printing = 1 << 1,
130     Template = 1 << 2,
131     Fetch    = 1 << 3
132   };
133   int m_initializedPages;
134   bool isPageInitialized(Page page) const;
135 
136   /**
137    * Sets-up the page for the general options.
138    */
139   void setupGeneralPage();
140   void initGeneralPage(QFrame* frame);
141   void readGeneralConfig();
142   void saveGeneralConfig();
143   /**
144    * Sets-up the page for printing options.
145    */
146   void setupPrintingPage();
147   void initPrintingPage(QFrame* frame);
148   void readPrintingConfig();
149   void savePrintingConfig();
150   /**
151    * Sets-up the page for template options.
152    */
153   void setupTemplatePage();
154   void initTemplatePage(QFrame* frame);
155   void readTemplateConfig();
156   void saveTemplateConfig();
157   /**
158    */
159   void setupFetchPage();
160   void initFetchPage(QFrame* frame);
161   void readFetchConfig();
162   void saveFetchConfig();
163 
164   FetcherInfoListItem* findItem(const QString& path) const;
165   void loadTemplateList();
166 
167   bool m_modifying;
168   bool m_okClicked;
169 
170   QRadioButton* m_rbImageInFile;
171   QRadioButton* m_rbImageInAppDir;
172   QRadioButton* m_rbImageInLocalDir;
173   QCheckBox* m_cbOpenLastFile;
174   QCheckBox* m_cbShowTipDay;
175   QCheckBox* m_cbEnableWebcam;
176   QCheckBox* m_cbCapitalize;
177   QCheckBox* m_cbFormat;
178   QLineEdit* m_leCapitals;
179   QLineEdit* m_leArticles;
180   QLineEdit* m_leSuffixes;
181   QLineEdit* m_lePrefixes;
182 
183   QCheckBox* m_cbPrintHeaders;
184   QCheckBox* m_cbPrintFormatted;
185   QCheckBox* m_cbPrintGrouped;
186   QSpinBox* m_imageWidthBox;
187   QSpinBox* m_imageHeightBox;
188 
189   GUI::ComboBox* m_templateCombo;
190   QPushButton* m_previewButton;
191   QFontComboBox* m_fontCombo;
192   QSpinBox* m_fontSizeInput;
193   KColorCombo* m_baseColorCombo;
194   KColorCombo* m_textColorCombo;
195   KColorCombo* m_highBaseColorCombo;
196   KColorCombo* m_highTextColorCombo;
197 
198   QListWidget* m_sourceListWidget;
199   QMap<FetcherInfoListItem*, Fetch::ConfigWidget*> m_configWidgets;
200   QList<Fetch::ConfigWidget*> m_newStuffConfigWidgets;
201   QList<Fetch::ConfigWidget*> m_removedConfigWidgets;
202   QPushButton* m_modifySourceBtn;
203   QPushButton* m_moveUpSourceBtn;
204   QPushButton* m_moveDownSourceBtn;
205   QPushButton* m_removeSourceBtn;
206   QPushButton* m_newStuffBtn;
207   QCheckBox* m_cbFilterSource;
208   GUI::CollectionTypeCombo* m_sourceTypeCombo;
209 };
210 
211 } // end namespace
212 #endif
213