2 KNode, the KDE newsreader
3 Copyright (c) 1999-2006 the KNode authors.
4 See file AUTHORS for details
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 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
16 #include <QRadioButton>
19 #include <QGridLayout>
21 #include <QVBoxLayout>
25 #include <kdatepicker.h>
27 #include <kmessagebox.h>
28 #include <klineedit.h>
30 #include "utilities.h"
31 #include "knnntpaccount.h"
32 #include "kngroupdialog.h"
33 #include "knglobals.h"
34 #include <QPushButton>
37 KNGroupDialog::KNGroupDialog( QWidget
*parent
, KNNntpAccount::Ptr a
) :
38 KNGroupBrowser(parent
, i18n("Subscribe to Newsgroups"),a
, User1
| User2
, true, i18n("New &List"), i18n("New &Groups...") )
40 rightLabel
->setText(i18n("Current changes:"));
41 subView
=new Q3ListView(page
);
42 subView
->addColumn(i18n("Subscribe To"));
43 unsubView
=new Q3ListView(page
);
44 unsubView
->addColumn(i18n("Unsubscribe From"));
46 QVBoxLayout
*protL
=new QVBoxLayout();
48 listL
->addLayout(protL
, 1,2);
49 protL
->addWidget(subView
);
50 protL
->addWidget(unsubView
);
55 connect(groupView
, SIGNAL(selectionChanged(Q3ListViewItem
*)),
56 this, SLOT(slotItemSelected(Q3ListViewItem
*)));
57 connect(groupView
, SIGNAL(selectionChanged()),
58 this, SLOT(slotSelectionChanged()));
59 connect(subView
, SIGNAL(selectionChanged(Q3ListViewItem
*)),
60 this, SLOT(slotItemSelected(Q3ListViewItem
*)));
61 connect(unsubView
, SIGNAL(selectionChanged(Q3ListViewItem
*)),
62 this, SLOT(slotItemSelected(Q3ListViewItem
*)));
64 connect(arrowBtn1
, SIGNAL(clicked()), this, SLOT(slotArrowBtn1()));
65 connect(arrowBtn2
, SIGNAL(clicked()), this, SLOT(slotArrowBtn2()));
67 connect( this, SIGNAL(user1Clicked()), SLOT(slotUser1()) );
68 connect( this, SIGNAL(user2Clicked()), SLOT(slotUser2()) );
70 KNHelper::restoreWindowSize("groupDlg", this, QSize(662,393)); // optimized for 800x600
72 setHelp("anc-fetch-group-list");
77 KNGroupDialog::~KNGroupDialog()
79 KNHelper::saveWindowSize("groupDlg", this->size());
84 void KNGroupDialog::itemChangedState(CheckItem
*it
, bool s
)
86 kDebug(5003) <<"KNGroupDialog::itemChangedState()";
88 if(itemInListView(unsubView
, it
->info
)) {
89 removeListItem(unsubView
, it
->info
);
90 setButtonDirection(btn2
, right
);
91 arrowBtn1
->setEnabled(false);
92 arrowBtn2
->setEnabled(true);
95 new GroupItem(subView
, it
->info
);
96 arrowBtn1
->setEnabled(false);
97 arrowBtn2
->setEnabled(false);
101 if(itemInListView(subView
, it
->info
)) {
102 removeListItem(subView
, it
->info
);
103 setButtonDirection(btn1
, right
);
104 arrowBtn1
->setEnabled(true);
105 arrowBtn2
->setEnabled(false);
108 new GroupItem(unsubView
, it
->info
);
109 arrowBtn1
->setEnabled(false);
110 arrowBtn2
->setEnabled(false);
117 void KNGroupDialog::updateItemState(CheckItem
*it
)
119 it
->setChecked( (it
->info
.subscribed
&& !itemInListView(unsubView
, it
->info
)) ||
120 (!it
->info
.subscribed
&& itemInListView(subView
, it
->info
)) );
122 if((it
->info
.subscribed
|| it
->info
.newGroup
) && it
->pixmap(0)==0)
123 it
->setPixmap(0, (it
->info
.newGroup
)? pmNew
:pmGroup
);
128 void KNGroupDialog::toSubscribe(QList
<KNGroupInfo
> *l
)
132 bool moderated
=false;
133 Q3ListViewItemIterator
it(subView
);
134 for(; it
.current(); ++it
) {
135 const KNGroupInfo
& info
= ((static_cast<GroupItem
*>(it
.current()))->info
);
137 if (info
.status
==KNGroup::moderated
)
140 if (moderated
) // warn the user
141 KMessageBox::information( knGlobals
.topWidget
,
142 i18n("You have subscribed to a moderated newsgroup.\nYour articles will not appear in the group immediately.\nThey have to go through a moderation process."),
143 QString(), "subscribeModeratedWarning" );
148 void KNGroupDialog::toUnsubscribe(QStringList
*l
)
151 Q3ListViewItemIterator
it(unsubView
);
152 for(; it
.current(); ++it
)
153 l
->append(((static_cast<GroupItem
*>(it
.current()))->info
).name
);
158 void KNGroupDialog::setButtonDirection(arrowButton b
, arrowDirection d
)
161 if(b
==btn1
&& dir1
!=d
) {
165 else if(b
==btn2
&& dir2
!=d
) {
172 btn
->setIcon(pmRight
);
174 btn
->setIcon(pmLeft
);
180 void KNGroupDialog::slotItemSelected(Q3ListViewItem
*it
)
182 const QObject
*s
=sender();
186 unsubView
->clearSelection();
187 groupView
->clearSelection();
188 arrowBtn2
->setEnabled(false);
189 arrowBtn1
->setEnabled(true);
190 setButtonDirection(btn1
, left
);
192 else if(s
==unsubView
) {
193 subView
->clearSelection();
194 groupView
->clearSelection();
195 arrowBtn1
->setEnabled(false);
196 arrowBtn2
->setEnabled(true);
197 setButtonDirection(btn2
, left
);
201 subView
->clearSelection();
202 unsubView
->clearSelection();
203 cit
=static_cast<CheckItem
*>(it
);
204 if(!cit
->isOn() && !itemInListView(subView
, cit
->info
) && !itemInListView(unsubView
, cit
->info
)) {
205 arrowBtn1
->setEnabled(true);
206 arrowBtn2
->setEnabled(false);
207 setButtonDirection(btn1
, right
);
209 else if(cit
->isOn() && !itemInListView(unsubView
, cit
->info
) && !itemInListView(subView
, cit
->info
)) {
210 arrowBtn2
->setEnabled(true);
211 arrowBtn1
->setEnabled(false);
212 setButtonDirection(btn2
, right
);
215 arrowBtn1
->setEnabled(false);
216 arrowBtn2
->setEnabled(false);
223 void KNGroupDialog::slotSelectionChanged()
225 if (!groupView
->selectedItem())
226 arrowBtn1
->setEnabled(false);
231 void KNGroupDialog::slotArrowBtn1()
234 CheckItem
*it
=static_cast<CheckItem
*>(groupView
->selectedItem());
236 new GroupItem(subView
, it
->info
);
237 it
->setChecked(true);
241 GroupItem
*it
=static_cast<GroupItem
*>(subView
->selectedItem());
243 changeItemState(it
->info
, false);
248 arrowBtn1
->setEnabled(false);
252 void KNGroupDialog::slotArrowBtn2()
255 CheckItem
*it
=static_cast<CheckItem
*>(groupView
->selectedItem());
257 new GroupItem(unsubView
, it
->info
);
258 it
->setChecked(false);
262 GroupItem
*it
=static_cast<GroupItem
*>(unsubView
->selectedItem());
264 changeItemState(it
->info
, true);
269 arrowBtn2
->setEnabled(false);
274 void KNGroupDialog::slotUser1()
276 leftLabel
->setText(i18n("Downloading groups..."));
277 enableButton(User1
,false);
278 enableButton(User2
,false);
279 emit(fetchList(a_ccount
));
284 void KNGroupDialog::slotUser2()
286 QDate lastDate
= a_ccount
->lastNewFetch();
287 KDialog
*dlg
= new KDialog( this );
288 dlg
->setCaption( i18n("New Groups") );
289 dlg
->setButtons( Ok
| Cancel
);
291 QGroupBox
*btnGrp
= new QGroupBox( i18n("Check for New Groups"), dlg
);
292 dlg
->setMainWidget(btnGrp
);
293 QGridLayout
*topL
= new QGridLayout( btnGrp
);
295 QRadioButton
*takeLast
= new QRadioButton( i18n("Created since last check:"), btnGrp
);
296 topL
->addWidget(takeLast
, 0, 0, 1, 2 );
298 QLabel
*l
= new QLabel(KGlobal::locale()->formatDate(lastDate
, KLocale::LongDate
),btnGrp
);
299 topL
->addWidget(l
, 1, 1, Qt::AlignLeft
);
301 connect(takeLast
, SIGNAL(toggled(bool)), l
, SLOT(setEnabled(bool)));
303 QRadioButton
*takeCustom
= new QRadioButton( i18n("Created since this date:"), btnGrp
);
304 topL
->addWidget(takeCustom
, 2, 0, 1, 2 );
306 dateSel
= new KDatePicker( lastDate
, btnGrp
);
307 dateSel
->setMinimumSize(dateSel
->sizeHint());
308 topL
->addWidget(dateSel
, 3, 1, Qt::AlignLeft
);
310 connect(takeCustom
, SIGNAL(toggled(bool)), this, SLOT(slotDatePickerEnabled(bool)));
312 takeLast
->setChecked(true);
313 dateSel
->setEnabled(false);
315 topL
->addItem( new QSpacerItem(30, 0 ), 0, 0 );
318 if (takeCustom
->isChecked())
319 lastDate
= dateSel
->date();
320 a_ccount
->setLastNewFetch(QDate::currentDate());
321 leftLabel
->setText(i18n("Checking for new groups..."));
322 enableButton(User1
,false);
323 enableButton(User2
,false);
325 subCB
->setChecked(false);
326 newCB
->setChecked(true);
327 emit(checkNew(a_ccount
,lastDate
));
328 incrementalFilter
=false;
335 void KNGroupDialog::slotDatePickerEnabled( bool b
)
337 dateSel
->setEnabled( b
);
341 //--------------------------------