akregator/src

propertiesdialog.cpp
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "akregatorconfig.h"
26 #include "feed.h"
27 #include "propertiesdialog.h"
28 
29 #include <kcombobox.h>
30 #include <klineedit.h>
31 #include <kpassdlg.h>
32 #include <tdelocale.h>
33 #include <knuminput.h>
34 
35 #include <tqcheckbox.h>
36 #include <tqbuttongroup.h>
37 #include <tqradiobutton.h>
38 
39 namespace Akregator {
40 
41 FeedPropertiesWidget::FeedPropertiesWidget(TQWidget *parent, const char *name)
42  : FeedPropertiesWidgetBase(parent, name)
43 {
44 }
45 
46 FeedPropertiesWidget::~FeedPropertiesWidget()
47 {}
48 
49 
50 void FeedPropertiesWidget::slotUpdateComboBoxActivated( int index )
51 {
52  if ( index == 3 ) // "never"
53  updateSpinBox->setEnabled(false);
54  else
55  updateSpinBox->setEnabled(true);
56 }
57 
58 
59 void FeedPropertiesWidget::slotUpdateCheckBoxToggled( bool enabled )
60 {
61  if (enabled && updateComboBox->currentItem() != 3 ) // "never"
62  updateSpinBox->setEnabled(true);
63  else
64  updateSpinBox->setEnabled(false);
65 }
66 
67 
68 FeedPropertiesDialog::FeedPropertiesDialog(TQWidget *parent, const char *name)
69  : KDialogBase(KDialogBase::Swallow, TQt::WStyle_DialogBorder, parent, name, true, i18n("Feed Properties"), KDialogBase::Ok|KDialogBase::Cancel)
70 {
71  widget=new FeedPropertiesWidget(this);
72  setMainWidget(widget);
73  widget->feedNameEdit->setFocus();
74 
75  connect(widget->feedNameEdit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(slotSetCaption(const TQString&)));
76 }
77 
78 FeedPropertiesDialog::~FeedPropertiesDialog()
79 {}
80 
81 void FeedPropertiesDialog::slotOk()
82 {
83  m_feed->setNotificationMode(false);
84  m_feed->setTitle( feedName() );
85  m_feed->setXmlUrl( url() );
86  m_feed->setCustomFetchIntervalEnabled(autoFetch());
87  if (autoFetch())
88  m_feed->setFetchInterval(fetchInterval());
89  m_feed->setArchiveMode(archiveMode());
90  m_feed->setMaxArticleAge(maxArticleAge());
91  m_feed->setMaxArticleNumber(maxArticleNumber());
92  m_feed->setMarkImmediatelyAsRead(markImmediatelyAsRead());
93  m_feed->setUseNotification(useNotification());
94  m_feed->setLoadLinkedWebsite(loadLinkedWebsite());
95  m_feed->setNotificationMode(true, true);
96 
97  KDialogBase::slotOk();
98 }
99 
100 void FeedPropertiesDialog::slotSetCaption(const TQString& c)
101 {
102  if(c.isEmpty())
103  setCaption(i18n("Feed Properties"));
104  else
105  setCaption(i18n("Properties of %1").arg(c));
106 
107 }
108 
109 void FeedPropertiesDialog::setFeed(Feed* feed)
110 {
111  m_feed = feed;
112  if (!feed)
113  return;
114 
115  setFeedName( feed->title() );
116  setUrl( feed->xmlUrl() );
117  setAutoFetch(feed->useCustomFetchInterval());
118  if (feed->useCustomFetchInterval())
119  setFetchInterval(feed->fetchInterval());
120  else
121  setFetchInterval(Settings::autoFetchInterval());
122  setArchiveMode(feed->archiveMode());
123  setMaxArticleAge(feed->maxArticleAge());
124  setMaxArticleNumber(feed->maxArticleNumber());
125  setMarkImmediatelyAsRead(feed->markImmediatelyAsRead());
126  setUseNotification(feed->useNotification());
127  setLoadLinkedWebsite(feed->loadLinkedWebsite());
128  slotSetCaption(feedName());
129 }
130 
131 
132 const TQString FeedPropertiesDialog::feedName() const
133 {
134  return widget->feedNameEdit->text();
135 }
136 
137 const TQString FeedPropertiesDialog::url() const
138 {
139  return widget->urlEdit->text();
140 }
141 
142 bool FeedPropertiesDialog::autoFetch() const
143 {
144  return widget->upChkbox->isChecked();
145 }
146 
147 int FeedPropertiesDialog::fetchInterval() const
148 {
149  switch (widget->updateComboBox->currentItem() )
150  {
151  case 0: // minutes
152  return widget->updateSpinBox->value();
153  case 1: // hours
154  return widget->updateSpinBox->value()*60;
155  case 2: // days
156  return widget->updateSpinBox->value()*60*24;
157  default:
158  return -1; // never
159  }
160 }
161 
162 Feed::ArchiveMode FeedPropertiesDialog::archiveMode() const
163 {
164  // i could check the button group's int, but order could change...
165  if ( widget->rb_globalDefault->isChecked() )
166  return Feed::globalDefault;
167 
168  if ( widget->rb_keepAllArticles->isChecked() )
169  return Feed::keepAllArticles;
170 
171  if ( widget->rb_limitArticleAge->isChecked() )
172  return Feed::limitArticleAge;
173 
174  if ( widget->rb_limitArticleNumber->isChecked() )
175  return Feed::limitArticleNumber;
176 
177  if ( widget->rb_disableArchiving->isChecked() )
178  return Feed::disableArchiving;
179 
180  // in a perfect world, this is never reached
181 
182  return Feed::globalDefault;
183 }
184 
185 
186 int FeedPropertiesDialog::maxArticleAge() const
187 {
188  return widget->sb_maxArticleAge->value();
189 }
190 
191 int FeedPropertiesDialog::maxArticleNumber() const
192 {
193  return widget->sb_maxArticleNumber->value();
194 }
195 
196 void FeedPropertiesDialog::setArchiveMode(Feed::ArchiveMode mode)
197  {
198  switch (mode)
199  {
200  case Feed::globalDefault:
201  widget->rb_globalDefault->setChecked(true);
202  break;
203  case Feed::keepAllArticles:
204  widget->rb_keepAllArticles->setChecked(true);
205  break;
206  case Feed::disableArchiving:
207  widget->rb_disableArchiving->setChecked(true);
208  break;
209  case Feed::limitArticleAge:
210  widget->rb_limitArticleAge->setChecked(true);
211  break;
212  case Feed::limitArticleNumber:
213  widget->rb_limitArticleNumber->setChecked(true);
214  }
215 }
216 void FeedPropertiesDialog::setFeedName(const TQString& title)
217 {
218  widget->feedNameEdit->setText(title);
219 }
220 
221 void FeedPropertiesDialog::setUrl(const TQString& url)
222 {
223  widget->urlEdit->setText(url);
224 }
225 
226 void FeedPropertiesDialog::setAutoFetch(bool customFetchEnabled)
227 {
228  widget->upChkbox->setChecked(customFetchEnabled);
229  widget->updateComboBox->setEnabled(customFetchEnabled);
230 
231  if (widget->updateSpinBox->value() > -1)
232  widget->updateSpinBox->setEnabled(customFetchEnabled);
233  else
234  widget->updateSpinBox->setEnabled(false);
235 }
236 
237 void FeedPropertiesDialog::setFetchInterval(int interval)
238 {
239  if (interval == -1) // never update
240  {
241  widget->updateSpinBox->setValue(0);
242  widget->updateSpinBox->setDisabled(true);
243  widget->updateComboBox->setCurrentItem(3); // never
244  return;
245  }
246 
247  if (interval == 0)
248  {
249  widget->updateSpinBox->setValue(0);
250  widget->updateSpinBox->setEnabled(widget->upChkbox->isChecked());
251  widget->updateComboBox->setCurrentItem(0); // minutes
252  return;
253  }
254 
255  if (interval % (60*24) == 0)
256  {
257  widget->updateSpinBox->setValue(interval / (60*24) );
258  widget->updateSpinBox->setEnabled(widget->upChkbox->isChecked());
259  widget->updateComboBox->setCurrentItem(2); // days
260  return;
261  }
262 
263  if (interval % 60 == 0)
264  {
265  widget->updateSpinBox->setValue(interval / 60 );
266  widget->updateSpinBox->setEnabled(widget->upChkbox->isChecked());
267  widget->updateComboBox->setCurrentItem(1); // hours
268  return;
269  }
270 
271  widget->updateSpinBox->setValue(interval);
272  widget->updateSpinBox->setEnabled(widget->upChkbox->isChecked());
273  widget->updateComboBox->setCurrentItem(0); // minutes
274 }
275 
276 void FeedPropertiesDialog::setMaxArticleAge(int age)
277  {
278  widget->sb_maxArticleAge->setValue(age);
279 }
280 
281 void FeedPropertiesDialog::setMaxArticleNumber(int number)
282 {
283  widget->sb_maxArticleNumber->setValue(number);
284 }
285 
286 void FeedPropertiesDialog::setMarkImmediatelyAsRead(bool enabled)
287 {
288  widget->checkBox_markRead->setChecked(enabled);
289 }
290 
291 bool FeedPropertiesDialog::markImmediatelyAsRead() const
292 {
293  return widget->checkBox_markRead->isChecked();
294 }
295 
296 void FeedPropertiesDialog::setUseNotification(bool enabled)
297 {
298  widget->checkBox_useNotification->setChecked(enabled);
299 }
300 
301 bool FeedPropertiesDialog::useNotification() const
302 {
303  return widget->checkBox_useNotification->isChecked();
304 }
305 
306 bool FeedPropertiesDialog::loadLinkedWebsite() const
307 {
308  return widget->checkBox_loadWebsite->isChecked();
309 }
310 
311 void FeedPropertiesDialog::setLoadLinkedWebsite(bool enabled)
312 {
313  widget->checkBox_loadWebsite->setChecked(enabled);
314 }
315 
316 void FeedPropertiesDialog::selectFeedName()
317 {
318  widget->feedNameEdit->selectAll();
319 }
320 
321 } // namespace Akregator
322 
323 #include "propertiesdialog.moc"