summaryrefslogtreecommitdiffstats
path: root/knode/knfilterdialog.cpp
blob: 399c0078b25683c59e7ae61497d1482ebe3ddecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
    knfilterdialog.cpp

    KNode, the KDE newsreader
    Copyright (c) 1999-2001 the KNode authors.
    See file AUTHORS for details

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/

#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqlayout.h>

#include <klocale.h>
#include <kmessagebox.h>
#include <klineedit.h>

#include "knglobals.h"
#include "knfiltermanager.h"
#include "knfilterconfigwidget.h"
#include "knarticlefilter.h"
#include "utilities.h"
#include "knfilterdialog.h"


KNFilterDialog::KNFilterDialog(KNArticleFilter *f, TQWidget *tqparent, const char *name)
  : KDialogBase(Plain, (f->id()==-1)? i18n("New Filter"):i18n("Properties of %1").tqarg(f->name()),
                Ok|Cancel|Help, Ok, tqparent, name),
    fltr(f)
{
  TQFrame* page=plainPage();

  TQGroupBox *gb=new TQGroupBox(page);
  fname=new KLineEdit(gb);
  TQLabel *l1=new TQLabel(fname, i18n("Na&me:"), gb);
  apon=new TQComboBox(gb);
  apon->insertItem(i18n("Single Articles"));
  apon->insertItem(i18n("Whole Threads"));
  TQLabel *l2=new TQLabel(apon, i18n("Apply o&n:"), gb);
  enabled=new TQCheckBox(i18n("Sho&w in menu"), gb);

  fw=new KNFilterConfigWidget(page);

  TQGridLayout *gbL=new TQGridLayout(gb, 2,4,8,5);
  gbL->addWidget(l1, 0,0);
  gbL->addMultiCellWidget(fname, 0,0,1,3);
  gbL->addWidget(enabled, 1,0);
  gbL->addWidget(l2, 1,2);
  gbL->addWidget(apon, 1,3);
  gbL->setColStretch(1,1);

  TQVBoxLayout *topL=new TQVBoxLayout(page,0,5);

  topL->addWidget(gb);
  topL->addWidget(fw,1);

  enabled->setChecked(f->isEnabled());
  apon->setCurrentItem((int) f->applyOn());
  fname->setText(f->translatedName());

  fw->status->setFilter(f->status);
  fw->lines->setFilter(f->lines);
  fw->age->setFilter(f->age);
  fw->score->setFilter(f->score);
  fw->subject->setFilter(f->subject);
  fw->from->setFilter(f->from);
  fw->messageId->setFilter(f->messageId);
  fw->references->setFilter(f->references);

  setFixedHeight(tqsizeHint().height());
  KNHelper::restoreWindowSize("filterDLG", this, tqsizeHint());

  setHelp("anc-using-filters");
  connect( fname,  TQT_SIGNAL( textChanged ( const TQString & )), this, TQT_SLOT( slotTextChanged( const TQString & )));
  slotTextChanged( fname->text() );
}



KNFilterDialog::~KNFilterDialog()
{
  KNHelper::saveWindowSize("filterDLG", size());
}

void KNFilterDialog::slotTextChanged( const TQString &_text )
{
    enableButtonOK( !_text.isEmpty() );
}

void KNFilterDialog::slotOk()
{
  if (fname->text().isEmpty())
    KMessageBox::sorry(this, i18n("Please provide a name for this filter."));
  else
    if (!knGlobals.filterManager()->newNameIsOK(fltr,fname->text()))
      KMessageBox::sorry(this, i18n("A filter with this name exists already.\nPlease choose a different name."));
    else {
      fltr->setTranslatedName(fname->text());
      fltr->setEnabled(enabled->isChecked());
      fltr->status=fw->status->filter();
      fltr->score=fw->score->filter();
      fltr->age=fw->age->filter();
      fltr->lines=fw->lines->filter();
      fltr->subject=fw->subject->filter();
      fltr->from=fw->from->filter();
      fltr->messageId=fw->messageId->filter();
      fltr->references=fw->references->filter();
      fltr->setApplyOn(apon->currentItem());

      accept();
    }
}



//--------------------------------

#include "knfilterdialog.moc"