2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 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
18 #include <QVBoxLayout>
19 #include <QGridLayout>
23 #include <kmessagebox.h>
24 #include <klineedit.h>
26 #include "knglobals.h"
27 #include "knfiltermanager.h"
28 #include "knfilterconfigwidget.h"
29 #include "knarticlefilter.h"
30 #include "utilities.h"
31 #include "knfilterdialog.h"
34 KNFilterDialog::KNFilterDialog( KNArticleFilter
*f
, QWidget
*parent
)
39 setCaption( i18n("New Filter") );
41 setCaption( i18n("Properties of %1", f
->name()) );
42 setButtons( Ok
|Cancel
|Help
);
43 setDefaultButton( Ok
);
45 QFrame
* page
= new QFrame( this );
46 setMainWidget( page
);
48 QGroupBox
*gb
= new QGroupBox( page
);
49 fname
=new KLineEdit(gb
);
50 QLabel
*l1
=new QLabel(i18n("Na&me:"),gb
);
52 apon
=new QComboBox(gb
);
53 apon
->addItem(i18n("Single Articles"));
54 apon
->addItem(i18n("Whole Threads"));
55 QLabel
*l2
=new QLabel(i18n("Apply o&n:"),gb
);
57 enabled
=new QCheckBox(i18n("Sho&w in menu"), gb
);
59 fw
=new KNFilterConfigWidget(page
);
61 QGridLayout
*gbL
=new QGridLayout(gb
);
64 gbL
->addWidget(l1
, 0,0);
65 gbL
->addWidget(fname
, 0,1, 1,3);
66 gbL
->addWidget(enabled
, 1,0);
67 gbL
->addWidget(l2
, 1,2);
68 gbL
->addWidget(apon
, 1,3);
69 gbL
->setColumnStretch(1,1);
71 QVBoxLayout
*topL
=new QVBoxLayout(page
);
76 topL
->addWidget(fw
,1);
78 enabled
->setChecked(f
->isEnabled());
79 apon
->setCurrentIndex((int) f
->applyOn());
80 fname
->setText(f
->translatedName());
82 fw
->status
->setFilter(f
->status
);
83 fw
->lines
->setFilter(f
->lines
);
84 fw
->age
->setFilter(f
->age
);
85 fw
->score
->setFilter(f
->score
);
86 fw
->subject
->setFilter(f
->subject
);
87 fw
->from
->setFilter(f
->from
);
88 fw
->messageId
->setFilter(f
->messageId
);
89 fw
->references
->setFilter(f
->references
);
91 setFixedHeight(sizeHint().height());
92 KNHelper::restoreWindowSize("filterDLG", this, sizeHint());
94 setHelp("anc-using-filters");
95 connect( fname
, SIGNAL(textChanged(QString
)), this, SLOT(slotTextChanged(QString
)));
96 connect( this, SIGNAL(okClicked()),this,SLOT(slotOk()));
97 slotTextChanged( fname
->text() );
102 KNFilterDialog::~KNFilterDialog()
104 KNHelper::saveWindowSize("filterDLG", size());
107 void KNFilterDialog::slotTextChanged( const QString
&_text
)
109 enableButtonOk( !_text
.isEmpty() );
112 void KNFilterDialog::slotOk()
114 if (fname
->text().isEmpty())
115 KMessageBox::sorry(this, i18n("Please provide a name for this filter."));
117 if (!knGlobals
.filterManager()->newNameIsOK(fltr
,fname
->text()))
118 KMessageBox::sorry(this, i18n("A filter with this name exists already.\nPlease choose a different name."));
120 fltr
->setTranslatedName(fname
->text());
121 fltr
->setEnabled(enabled
->isChecked());
122 fltr
->status
=fw
->status
->filter();
123 fltr
->score
=fw
->score
->filter();
124 fltr
->age
=fw
->age
->filter();
125 fltr
->lines
=fw
->lines
->filter();
126 fltr
->subject
=fw
->subject
->filter();
127 fltr
->from
=fw
->from
->filter();
128 fltr
->messageId
=fw
->messageId
->filter();
129 fltr
->references
=fw
->references
->filter();
130 fltr
->setApplyOn(apon
->currentIndex());
138 //--------------------------------
140 #include "knfilterdialog.moc"