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
177
178
179
180
181
182
183
184
185
|
/***************************************************************************
kxeprocinstrdialog.cpp - description
-------------------
begin : Mit Apr 24 2002
copyright : (C) 2002, 2003 by The KXMLEditor Team
email : lvanek@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "kxeprocinstrdialog.h"
#include <tqlabel.h>
#include <tqcombobox.h>
#include <tqpushbutton.h>
#include <tqtextedit.h>
#include <klineedit.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
KXEProcInstrDialog::KXEProcInstrDialog( TQWidget * pParent, const char * pszName, bool fModal, WFlags fl )
: KXEProcInstrDialogBase( pParent, pszName, fModal, fl )
{
// signals and slots connections
connect( m_pBtnOK, SIGNAL( clicked() ), this, SLOT( slotAccept() ) );
connect( m_pEditData, SIGNAL(textChanged()), this, SLOT(slotDataChanged()) );
connect( m_pEditTarget, SIGNAL(textChanged(const TQString &)), this, SLOT(slotTargetChanged(const TQString &)) );
}
void KXEProcInstrDialog::clearDialog()
{
m_pEditTarget->clear();
m_pEditData->clear();
}
int KXEProcInstrDialog::exec( bool bEditExisting, bool bParentIsDocument )
{
if(bEditExisting)
{
m_pComboInsert->hide();
m_pComboInsert->setDisabled(true);
m_pLblInsert->hide();
m_pLblInsert->setDisabled(true);
m_pEditTarget->setDisabled(true);
m_pEditTarget->setText( m_strTarget );
m_pEditData->setText( m_strData );
}
else
{
if ( bParentIsDocument )
{
m_pComboInsert->hide();
m_pComboInsert->setDisabled(true);
m_pLblInsert->hide();
m_pLblInsert->setDisabled(true);
}
m_pEditTarget->setEnabled(true);
clearDialog();
}
int iReturn = exec();
if ( iReturn == Accepted )
{
m_bAtTop = ( m_pComboInsert->currentItem() == 0 );
m_strTarget = m_pEditTarget->text();
m_strData = m_pEditData->text();
}
return iReturn;
}
int KXEProcInstrDialog::exec()
{
if ( m_pEditTarget->text().isEmpty() )
m_pBtnOK->setEnabled(false);
else
m_pBtnOK->setEnabled(true);
if ( m_pEditTarget->isEnabled() )
m_pEditTarget->setFocus();
else
m_pEditData->setFocus();
m_pBtnOK->setDefault(true);
return KXEProcInstrDialogBase::exec();
}
void KXEProcInstrDialog::slotDataChanged()
{
TQString strMessage = checkData(m_pEditData->text());
if(strMessage.isEmpty())
strMessage = checkTarget(m_pEditTarget->text());
m_pTextLabelMessage->setText(strMessage);
if ( m_pEditData->text().isEmpty() ||
m_pEditTarget->text().isEmpty() ||
(strMessage.length() > 0)
)
m_pBtnOK->setDisabled(true);
else
m_pBtnOK->setEnabled(true);
}
void KXEProcInstrDialog::slotTargetChanged(const TQString &strNewTarget)
{
TQString strMessage = checkTarget(strNewTarget);
if(strMessage.isEmpty())
strMessage = checkData(m_pEditData->text());
m_pTextLabelMessage->setText(strMessage);
if ( m_pEditData->text().isEmpty() ||
strNewTarget.isEmpty() ||
(strMessage.length() > 0)
)
m_pBtnOK->setDisabled(true);
else
m_pBtnOK->setEnabled(true);
}
/** Called when user press OK button */
void KXEProcInstrDialog::slotAccept()
{
if(m_pEditTarget->text() == "xml")
{ KMessageBox::sorry(this, i18n("Pleasse use menu item File -> Version and encoding for this processing instruction !"));
return;
}
accept();
}
// Check, if XML proc. instr. target is OK
TQString KXEProcInstrDialog::checkTarget(const TQString strTarget)
{
if(strTarget.length() == 0)
return "";
// Forbidden characters
TQString strForbiddenChars("<>");
for(unsigned int i = 0; i < strForbiddenChars.length(); i++)
{
TQChar ch = strForbiddenChars[i];
if(strTarget.find(ch) >= 0)
return i18n("Target cannot contain character: %1 !").arg(ch);
}
return "";
}
// Check, if XML proc. instr. data is OK
TQString KXEProcInstrDialog::checkData(const TQString strData)
{
if(strData.length() == 0)
return "";
// Forbidden characters
TQString strForbiddenChars("<>");
for(unsigned int i = 0; i < strForbiddenChars.length(); i++)
{
TQChar ch = strForbiddenChars[i];
if(strData.find(ch) >= 0)
return i18n("Contents cannot contain character: %1 !").arg(ch);
}
return "";
}
#include "kxeprocinstrdialog.moc"
|