summaryrefslogtreecommitdiffstats
path: root/konq-plugins/validators/validatorsdialog.cpp
blob: bd0e4d944d67c5676b771a767500bc888732c87d (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* This file is part of the KDE project

   Copyright (C) 2001 Andreas Schlapbach <schlpbch@iam.unibe.ch>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <tqlabel.h>
#include <tqvbox.h>
#include <tqgroupbox.h>
#include <tqlayout.h>
#include <tqcombobox.h>
#include <kconfig.h>

#include <klocale.h>

#include "validatorsdialog.h"
#include "validatorsdialog.moc"

ValidatorsDialog::ValidatorsDialog(TQWidget *tqparent,  const char *name )
  : KDialogBase( tqparent, name, false, i18n("Configure"), Ok|Cancel, Ok, true )
{
  setCaption(i18n("Configure Validating Servers"));
  setMinimumWidth(300);

  TQVBox *page = makeVBoxMainWidget ();

  TQGroupBox *tgroup = new TQGroupBox( i18n("HTML/XML Validator"), page );
  TQVBoxLayout *vlay = new TQVBoxLayout( tgroup, spacingHint() );
  vlay->addSpacing( fontMetrics().lineSpacing());

  vlay->addWidget(new TQLabel( i18n("URL:"), tgroup));

  m_WWWValidatorCB = new TQComboBox(true, tgroup);
  m_WWWValidatorCB->setDuplicatesEnabled(false);
  vlay->addWidget( m_WWWValidatorCB );

  vlay->addWidget(new TQLabel( i18n("Upload:"), tgroup));

  m_WWWValidatorUploadCB = new TQComboBox(true, tgroup);
  m_WWWValidatorUploadCB->setDuplicatesEnabled(false);
  vlay->addWidget( m_WWWValidatorUploadCB );

  ///

  TQGroupBox *group2= new TQGroupBox( i18n("CSS Validator"), page );
  TQVBoxLayout *vlay2 = new TQVBoxLayout( group2, spacingHint() );
  vlay2->addSpacing( fontMetrics().lineSpacing());

  vlay2->addWidget(new TQLabel( i18n("URL:"), group2));

  m_CSSValidatorCB = new TQComboBox(true, group2);
  m_CSSValidatorCB->setDuplicatesEnabled(false);
  vlay2->addWidget( m_CSSValidatorCB );

  vlay2->addWidget(new TQLabel( i18n("Upload:"), group2));

  m_CSSValidatorUploadCB = new TQComboBox(true, group2);
  m_CSSValidatorUploadCB->setDuplicatesEnabled(false);
  vlay2->addWidget( m_CSSValidatorUploadCB );

  ///

  TQGroupBox *group3= new TQGroupBox( i18n("Link Validator"), page );
  TQVBoxLayout *vlay3 = new TQVBoxLayout( group3, spacingHint() );
  vlay3->addSpacing( fontMetrics().lineSpacing());

  vlay3->addWidget(new TQLabel( i18n("URL:"), group3));

  m_linkValidatorCB = new TQComboBox(true, group3);
  m_linkValidatorCB->setDuplicatesEnabled(false);
  vlay3->addWidget( m_linkValidatorCB );

  load();
}

ValidatorsDialog::~ValidatorsDialog()
{
    delete m_config;
}

void ValidatorsDialog::load()
{
  m_config = new KConfig("validatorsrc");
  m_config->setGroup("Addresses");

  m_WWWValidatorCB->insertStringList(m_config->readListEntry("WWWValidatorUrl"));
  if (m_WWWValidatorCB->count()==0) {
    m_WWWValidatorCB->insertItem("http://validator.w3.org/check");
  }
  m_WWWValidatorCB->setCurrentItem(m_config->readNumEntry("WWWValidatorUrlIndex",0));

  m_CSSValidatorCB->insertStringList(m_config->readListEntry("CSSValidatorUrl"));
  if (m_CSSValidatorCB->count()==0) {
    m_CSSValidatorCB->insertItem("http://jigsaw.w3.org/css-validator/validator");
  }
  m_CSSValidatorCB->setCurrentItem(m_config->readNumEntry("CSSValidatorUrlIndex",0));

  m_linkValidatorCB->insertStringList(m_config->readListEntry("LinkValidatorUrl"));
  if (m_linkValidatorCB->count()==0) {
    m_linkValidatorCB->insertItem("http://validator.w3.org/checklink");
  }
  m_linkValidatorCB->setCurrentItem(m_config->readNumEntry("LinkValidatorUrlIndex",0));

  m_WWWValidatorUploadCB->insertStringList(m_config->readListEntry("WWWValidatorUploadUrl"));
  if (m_WWWValidatorUploadCB->count()==0) {
    m_WWWValidatorUploadCB->insertItem("http://validator.w3.org/file-upload.html");
  }
  m_WWWValidatorUploadCB->setCurrentItem(m_config->readNumEntry("WWWValidatorUploadUrlIndex",0));

  m_CSSValidatorUploadCB->insertStringList(m_config->readListEntry("CSSValidatorUploadUrl"));
  if (m_CSSValidatorUploadCB->count()==0) {
    m_CSSValidatorUploadCB->insertItem("http://jigsaw.w3.org/css-validator/validator-upload.html" );
  }
  m_CSSValidatorUploadCB->setCurrentItem(m_config->readNumEntry("CSSValidatorUploadUrlIndex",0));
}

void ValidatorsDialog::save()
{
  TQStringList strList;
  for (int i = 0; i < m_WWWValidatorCB->count(); i++) {
    strList.append(m_WWWValidatorCB->text(i));
  }
  m_config->writeEntry( "WWWValidatorUrl", strList );
  strList.clear();
  for (int i = 0; i < m_CSSValidatorCB->count(); i++) {
    strList.append(m_CSSValidatorCB->text(i));
  }
  m_config->writeEntry( "CSSValidatorUrl", strList );
  strList.clear();
  for (int i = 0; i < m_linkValidatorCB->count(); i++) {
    strList.append(m_linkValidatorCB->text(i));
  }
  m_config->writeEntry( "LinkValidatorUrl", strList );
  strList.clear();
  for (int i = 0; i < m_WWWValidatorUploadCB->count(); i++) {
    strList.append(m_WWWValidatorUploadCB->text(i));
  }
  m_config->writeEntry( "WWWValidatorUploadUrl", strList );
  strList.clear();
  for (int i = 0; i < m_CSSValidatorUploadCB->count(); i++) {
    strList.append(m_CSSValidatorUploadCB->text(i));
  }
  m_config->writeEntry( "CSSValidatorUploadUrl", strList );

  m_config->writeEntry( "WWWValidatorUrlIndex", m_WWWValidatorCB->currentItem() );
  m_config->writeEntry( "CSSValidatorUrlIndex", m_CSSValidatorCB->currentItem() );
  m_config->writeEntry( "LinkValidatorUrlIndex", m_linkValidatorCB->currentItem() );
  m_config->writeEntry( "WWWValidatorUploadUrlIndex", m_WWWValidatorUploadCB->currentItem() );
  m_config->writeEntry( "CSSValidatorUploadUrlIndex", m_CSSValidatorUploadCB->currentItem() );
  m_config->sync();
}

void ValidatorsDialog::slotOk()
{
   save();
   hide();
}

void ValidatorsDialog::slotCancel()
{
   load();
   hide();
}