32 #include <KMessageBox>
33 #include <KPushButton>
38 #include <QtGui/QFormLayout>
39 #include <QtGui/QLayout>
40 #include <QtGui/QCheckBox>
41 #include <QtGui/QLabel>
42 #include <QtGui/QGroupBox>
53 QVBoxLayout* baseLayout =
new QVBoxLayout(
this );
54 baseLayout->setMargin( 0 );
57 QHBoxLayout* directionCharsetLayout =
new QHBoxLayout();
59 mDirectionComboBox =
new KComboBox(
this );
60 const QStringList directionList = QStringList()
61 << i18nc(
"@item:inmenu Is converted _from_ charset (selected in combobox next to this)",
63 << i18nc(
"@item:inmenu Is converted _to_ charset (selected in combobox next to this)",
65 mDirectionComboBox->addItems( directionList );
68 const QString directionToolTip =
69 i18nc(
"@info:tooltip",
70 "The direction the bytes are converted, to or from the selected charset." );
71 mDirectionComboBox->setToolTip( directionToolTip );
72 const QString directionWhatsThis =
73 i18nc(
"@info:whatsthis",
74 "Select the direction the bytes are converted, to or from the selected charset." );
75 mDirectionComboBox->setWhatsThis( directionWhatsThis );
76 connect( mDirectionComboBox, SIGNAL(activated(
int)),
77 mTool, SLOT(setConversionDirection(
int)) );
79 directionCharsetLayout->addWidget( mDirectionComboBox );
81 mOtherCharSetComboBox =
new KComboBox(
this );
83 const int indexOfCurrentCharCodec = charCodecNames.indexOf( mTool->
otherCharCodecName() );
84 mOtherCharSetComboBox->addItems( charCodecNames );
85 mOtherCharSetComboBox->setCurrentIndex( indexOfCurrentCharCodec );
87 const QString targetCharsetToolTip =
88 i18nc(
"@info:tooltip",
89 "The charset the bytes are converted to." );
90 mOtherCharSetComboBox->setToolTip( targetCharsetToolTip );
91 const QString targetCharsetWhatsThis =
92 i18nc(
"@info:whatsthis",
93 "Select the charset the bytes are converted to." );
94 mOtherCharSetComboBox->setWhatsThis( targetCharsetWhatsThis );
95 connect( mOtherCharSetComboBox, SIGNAL(activated(QString)),
96 mTool, SLOT(setOtherCharCodecName(QString)) );
98 directionCharsetLayout->addWidget( mOtherCharSetComboBox, 10 );
99 baseLayout->addLayout( directionCharsetLayout );
102 QGroupBox* settingsBox =
new QGroupBox( i18nc(
"@title:group",
"Parameters"),
this );
104 QFormLayout* settingsLayout =
new QFormLayout();
106 const QString substituteMissingCharLabelText =
107 i18nc(
"@option:check substitute bytes whose char is not part of the target charset",
108 "Substitute missing:" );
109 mSubstituteMissingCharCheckBox =
new QCheckBox(
this );
111 const QString substituteMissingCharToolTip =
112 i18nc(
"@info:tooltip",
113 "Selects if bytes should be substituted with a default byte "
114 "if its char in the source charset is not part of the target charset." );
115 const QString substituteMissingCharWhatsThis =
116 i18nc(
"@info:whatsthis",
117 "Set to true if bytes should be substituted with a default byte "
118 "if its char in the source charset is not part of the target charset." );
119 mSubstituteMissingCharCheckBox->setToolTip( substituteMissingCharToolTip );
120 mSubstituteMissingCharCheckBox->setWhatsThis( substituteMissingCharWhatsThis );
121 connect( mSubstituteMissingCharCheckBox, SIGNAL(toggled(
bool)),
122 mTool, SLOT(setSubstitutingMissingChars(
bool)) );
123 settingsLayout->addRow( substituteMissingCharLabelText, mSubstituteMissingCharCheckBox );
131 const QString substituteByteLabelText =
132 i18nc(
"@label:textbox byte to use for chars which are not part of the target charset",
133 "Substitute byte:" );
137 const QString substituteByteToolTip =
138 i18nc(
"@info:tooltip",
139 "The byte to use for chars which are not part of the target charset." );
140 const QString substituteByteWhatsThis =
141 i18nc(
"@info:whatsthis",
142 "Define the byte to use for chars which are not part of the target charset." );
143 mSubstituteByteEdit->setToolTip( substituteByteToolTip );
144 mSubstituteByteEdit->setWhatsThis( substituteByteWhatsThis );
146 mSubstituteByteEdit->setEnabled(
false );
147 connect( mSubstituteByteEdit, SIGNAL(byteArrayChanged(QByteArray)),
148 SLOT(onDefaultByteEditChanged(QByteArray)) );
152 settingsLayout->addRow( substituteByteLabelText, mSubstituteByteEdit );
154 settingsBox->setLayout( settingsLayout );
156 baseLayout->addWidget( settingsBox );
159 QHBoxLayout* actionsLayout =
new QHBoxLayout();
161 actionsLayout->addStretch();
163 const KGuiItem convertGuiItem =
164 KGuiItem( i18n(
"Con&vert"),
165 QLatin1String(
"run-build"),
166 i18nc(
"@info:tooltip",
167 "Converts the bytes in the selected range."),
168 i18nc(
"@info:whatsthis",
169 "If you press the <interface>Convert</interface> button, "
170 "all bytes in the selected range "
171 "will be replaced by bytes which represent the same character "
172 "in the selected target charset.") );
173 mConvertButton =
new KPushButton( convertGuiItem,
this );
174 connect( mConvertButton, SIGNAL(clicked(
bool)), SLOT(onConvertButtonClicked()) );
175 actionsLayout->addWidget( mConvertButton );
177 baseLayout->addLayout( actionsLayout );
178 baseLayout->addStretch();
180 connect( mTool, SIGNAL(isApplyableChanged(
bool)),
181 SLOT(onApplyableChanged(
bool)) );
187 void CharsetConversionView::onApplyableChanged(
bool isApplyable )
189 mConvertButton->setEnabled( isApplyable );
192 void CharsetConversionView::onDefaultByteEditChanged(
const QByteArray& byteArray )
194 Q_UNUSED( byteArray );
197 void CharsetConversionView::onConvertButtonClicked()
202 void CharsetConversionView::onConversionDone(
bool success,
int convertedBytesCount,
206 const QString messageBoxTitle = mTool->
title();
210 QString conversionReport = (convertedBytesCount==0) ?
211 i18nc(
"@info",
"No bytes converted.") :
212 i18ncp(
"@info",
"1 byte converted.",
"%1 bytes converted.", convertedBytesCount );
215 int totalFailedByteCount = 0;
216 foreach(
int failedByteCount, failedPerByteCount )
217 totalFailedByteCount += failedByteCount;
219 conversionReport += QLatin1String(
"<br />" );
220 conversionReport += (totalFailedByteCount==0) ?
221 i18nc(
"@info",
"No bytes substituted.") :
222 i18ncp(
"@info",
"1 byte substituted.",
"%1 bytes substituted.", totalFailedByteCount );
224 KMessageBox::information( 0,
231 KMessageBox::sorry( 0,
233 "Conversion cancelled because of chars which are not "
234 "in the target charset."),
void setMaxLength(int maxLength)
void setByteArray(const QByteArray &byteArray)
void setMinLength(int minLength)
static const QStringList & codecNames()
virtual ~CharsetConversionView()
CharsetConversionView(CharsetConversionTool *tool, QWidget *parent=0)