split message into several paras and fix file extension markup
[kdepim.git] / knode / kngroupdialog.cpp
blobda944d474519e60d2d360cb4f6bcb74f0b419364
1 /*
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
15 #include <QLabel>
16 #include <QRadioButton>
17 #include <QCheckBox>
19 #include <QGridLayout>
20 #include <QGroupBox>
21 #include <QVBoxLayout>
23 #include <kdebug.h>
24 #include <kglobal.h>
25 #include <kdatepicker.h>
26 #include <klocale.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();
47 protL->setSpacing(3);
48 listL->addLayout(protL, 1,2);
49 protL->addWidget(subView);
50 protL->addWidget(unsubView);
52 dir1=right;
53 dir2=left;
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()";
87 if(s){
88 if(itemInListView(unsubView, it->info)) {
89 removeListItem(unsubView, it->info);
90 setButtonDirection(btn2, right);
91 arrowBtn1->setEnabled(false);
92 arrowBtn2->setEnabled(true);
94 else {
95 new GroupItem(subView, it->info);
96 arrowBtn1->setEnabled(false);
97 arrowBtn2->setEnabled(false);
100 else {
101 if(itemInListView(subView, it->info)) {
102 removeListItem(subView, it->info);
103 setButtonDirection(btn1, right);
104 arrowBtn1->setEnabled(true);
105 arrowBtn2->setEnabled(false);
107 else {
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)
130 l->clear();
132 bool moderated=false;
133 Q3ListViewItemIterator it(subView);
134 for(; it.current(); ++it) {
135 const KNGroupInfo& info = ((static_cast<GroupItem*>(it.current()))->info);
136 l->append(info);
137 if (info.status==KNGroup::moderated)
138 moderated=true;
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)
150 l->clear();
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)
160 QPushButton *btn=0;
161 if(b==btn1 && dir1!=d) {
162 btn=arrowBtn1;
163 dir1=d;
165 else if(b==btn2 && dir2!=d) {
166 btn=arrowBtn2;
167 dir2=d;
170 if(btn) {
171 if(d==right)
172 btn->setIcon(pmRight);
173 else
174 btn->setIcon(pmLeft);
180 void KNGroupDialog::slotItemSelected(Q3ListViewItem *it)
182 const QObject *s=sender();
185 if(s==subView) {
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);
199 else {
200 CheckItem *cit;
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);
214 else {
215 arrowBtn1->setEnabled(false);
216 arrowBtn2->setEnabled(false);
223 void KNGroupDialog::slotSelectionChanged()
225 if (!groupView->selectedItem())
226 arrowBtn1->setEnabled(false);
231 void KNGroupDialog::slotArrowBtn1()
233 if(dir1==right) {
234 CheckItem *it=static_cast<CheckItem*>(groupView->selectedItem());
235 if (it) {
236 new GroupItem(subView, it->info);
237 it->setChecked(true);
240 else {
241 GroupItem *it=static_cast<GroupItem*>(subView->selectedItem());
242 if (it) {
243 changeItemState(it->info, false);
244 delete it;
248 arrowBtn1->setEnabled(false);
252 void KNGroupDialog::slotArrowBtn2()
254 if(dir2==right) {
255 CheckItem *it=static_cast<CheckItem*>(groupView->selectedItem());
256 if (it) {
257 new GroupItem(unsubView, it->info);
258 it->setChecked(false);
261 else {
262 GroupItem *it=static_cast<GroupItem*>(unsubView->selectedItem());
263 if (it) {
264 changeItemState(it->info, true);
265 delete it;
269 arrowBtn2->setEnabled(false);
273 // new list
274 void KNGroupDialog::slotUser1()
276 leftLabel->setText(i18n("Downloading groups..."));
277 enableButton(User1,false);
278 enableButton(User2,false);
279 emit(fetchList(a_ccount));
283 // new groups
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 );
317 if (dlg->exec()) {
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);
324 filterEdit->clear();
325 subCB->setChecked(false);
326 newCB->setChecked(true);
327 emit(checkNew(a_ccount,lastDate));
328 incrementalFilter=false;
329 slotRefilter();
332 delete dlg;
335 void KNGroupDialog::slotDatePickerEnabled( bool b )
337 dateSel->setEnabled( b );
341 //--------------------------------
343 #include "kngroupdialog.moc"