tdefilereplace: simplified format of kfr files for string lists.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/11/head
Michele Calgaro 5 years ago
parent 588b1440b5
commit bfd50121e0
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -1570,8 +1570,7 @@ void TDEFileReplacePart::loadViewContent()
void TDEFileReplacePart::loadRulesFile(const TQString& fileName) void TDEFileReplacePart::loadRulesFile(const TQString& fileName)
{ {
/* Loads a file with kfr extension. // Loads a file with kfr extension, creates a xml document and browses it
* creates a xml document and browses it*/
TQDomDocument doc("mydocument"); TQDomDocument doc("mydocument");
TQFile file(fileName); TQFile file(fileName);
TDEListView* sv = m_view->getStringsView(); TDEListView* sv = m_view->getStringsView();
@ -1636,7 +1635,7 @@ void TDEFileReplacePart::loadRulesFile(const TQString& fileName)
n = n.nextSibling(); n = n.nextSibling();
} }
// Adds file to "load strings form file" menu // Adds file to "load strings from file" menu
TQStringList fileList = m_option->m_recentStringFileList; TQStringList fileList = m_option->m_recentStringFileList;
if(!fileList.contains(fileName)) if(!fileList.contains(fileName))
{ {

@ -466,54 +466,47 @@ void TDEFileReplaceView::slotStringsEdit()
void TDEFileReplaceView::slotStringsSave() void TDEFileReplaceView::slotStringsSave()
{ {
// Check there are strings in the list // Check there are strings in the list
TDEListView* sv = getStringsView(); TDEListView *sv = getStringsView();
if (!sv->firstChild())
if (sv->firstChild() == 0)
{ {
KMessageBox::error(0, i18n("No strings to save as the list is empty.")); KMessageBox::error(0, i18n("No strings to save as the list is empty."));
return ; return;
} }
TQString header("<?xml version=\"1.0\" ?>\n<kfr>"), TQString header("<?xml version=\"1.0\" ?>\n<kfr>"), footer("\n</kfr>"), body;
footer("\n</kfr>"),
body;
if(m_option->m_searchingOnlyMode) if(m_option->m_searchingOnlyMode)
header += "\n\t<mode search=\"true\"/>"; header += "\n\t<mode search=\"true\"/>";
else else
header += "\n\t<mode search=\"false\"/>"; header += "\n\t<mode search=\"false\"/>";
TQListViewItem* lvi = sv->firstChild(); TQListViewItem *lvi = sv->firstChild();
while( lvi ) while (lvi)
{ {
body += TQString("\n\t<replacement>" body += TQString("\n\t<replacement>"
"\n\t\t<oldstring><![CDATA[%1]]></oldstring>" "\n\t\t<oldstring>%1</oldstring>"
"\n\t\t<newstring><![CDATA[%2]]></newstring>" "\n\t\t<newstring>%2</newstring>"
"\n\t</replacement>").arg(lvi->text(0)).arg(lvi->text(1)); "\n\t</replacement>").arg(lvi->text(0)).arg(lvi->text(1));
lvi = lvi->nextSibling(); lvi = lvi->nextSibling();
} }
// Selects the file where strings will be saved // Selects the file where strings will be saved
TQString menu = "*.kfr|" + i18n("TDEFileReplace Strings") + " (*.kfr)\n*|" + i18n("All Files") + " (*)"; TQString menu = "*.kfr|" + i18n("TDEFileReplace Strings") + " (*.kfr)\n*|" + i18n("All Files") + " (*)";
TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, 0, i18n("Save Strings to File")); TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, 0, i18n("Save Strings to File"));
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
// Forces the extension to be "kfr" == TDEFileReplace extension // Forces the extension to be "kfr" == TDEFileReplace extension
fileName = TDEFileReplaceLib::addExtension(fileName, "kfr"); fileName = TDEFileReplaceLib::addExtension(fileName, "kfr");
TQFile file(fileName);
TQFile file( fileName ); if(!file.open(IO_WriteOnly))
if(!file.open( IO_WriteOnly ))
{ {
KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName)); KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
return ; return ;
} }
TQTextStream oTStream( &file ); TQTextStream oTStream(&file);
oTStream.setEncoding(TQTextStream::UnicodeUTF8); oTStream.setEncoding(TQTextStream::UnicodeUTF8);
oTStream << header oTStream << header << body << footer;
<< body
<< footer;
file.close(); file.close();
} }
@ -726,7 +719,6 @@ void TDEFileReplaceView::loadMapIntoView(KeyValueMap map)
{ {
m_sv->clear(); m_sv->clear();
KeyValueMap::Iterator itMap; KeyValueMap::Iterator itMap;
for(itMap = map.begin(); itMap != map.end(); ++itMap) for(itMap = map.begin(); itMap != map.end(); ++itMap)
{ {
TQListViewItem* lvi = new TQListViewItem(m_sv); TQListViewItem* lvi = new TQListViewItem(m_sv);

Loading…
Cancel
Save