summaryrefslogtreecommitdiffstats
path: root/tdefilereplace/tdefilereplaceview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdefilereplace/tdefilereplaceview.cpp')
-rw-r--r--tdefilereplace/tdefilereplaceview.cpp78
1 files changed, 77 insertions, 1 deletions
diff --git a/tdefilereplace/tdefilereplaceview.cpp b/tdefilereplace/tdefilereplaceview.cpp
index b147da7..ca6587f 100644
--- a/tdefilereplace/tdefilereplaceview.cpp
+++ b/tdefilereplace/tdefilereplaceview.cpp
@@ -19,6 +19,7 @@
#include <tqwhatsthis.h>
#include <tqmap.h>
#include <tqfileinfo.h>
+#include <tqdom.h>
// KDE
#include <tdelistview.h>
@@ -407,6 +408,81 @@ void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const
}
}
+void TDEFileReplaceView::slotStringsLoad()
+{
+ // Selects the file to load from
+ TQString menu = "*.kfr|" + i18n("TDEFileReplace strings") + " (*.kfr)\n*|"+i18n("All Files") + " (*)";
+ TQString fileName = KFileDialog::getOpenFileName(TQString(), menu, this, i18n("Load Strings From File"));
+ if (fileName.isEmpty())
+ {
+ return;
+ }
+
+ // Loads a file with kfr extension, creates a xml document and browses it
+ TQDomDocument doc("mydocument");
+ TQFile file(fileName);
+ TDEListView *sv = getStringsView();
+ if (!file.open(IO_ReadOnly))
+ {
+ KMessageBox::error(this, i18n("<qt>Cannot open the file <b>%1</b> and load the string list.</qt>").arg(fileName));
+ return;
+ }
+
+ if(!doc.setContent(&file))
+ {
+ file.close();
+
+ KMessageBox::information(this, i18n("<qt>File <b>%1</b> seems not to be written in a valid kfr format.</qt>").arg(fileName), i18n("Warning"));
+ return;
+ }
+ else
+ {
+ file.close();
+ }
+
+ //clears view
+ sv->clear();
+
+ TQDomElement docElem = doc.documentElement();
+ TQDomNode n = docElem.firstChild();
+ TQString searchAttribute = n.toElement().attribute("search").latin1();
+ if (searchAttribute.isNull() || searchAttribute.isEmpty())
+ {
+ int answer = KMessageBox::warningYesNo(this, i18n("<qt>Missing search type. Is this a search-and-replace list of strings?</qt>").arg(fileName),i18n("Warning"),i18n("Yes"),i18n("No"));
+ if (answer == KMessageBox::Yes)
+ {
+ m_option->m_searchingOnlyMode = false;
+ }
+ else
+ {
+ m_option->m_searchingOnlyMode = true;
+ }
+ }
+
+ // Refreshes the view appearances
+ changeView(m_option->m_searchingOnlyMode);
+
+ // Reads the string list
+ KeyValueMap docMap;
+ n = n.nextSibling();
+ while (!n.isNull())
+ {
+ TQDomElement e = n.toElement(); // tries to convert the node to an element.
+ if (!e.isNull())
+ {
+ TQString searchString = e.firstChild().toElement().text();
+ TQString replaceString = e.lastChild().toElement().text();
+ docMap[searchString] = replaceString;
+ }
+ n = n.nextSibling();
+ }
+
+ changeView(m_option->m_searchingOnlyMode);
+ loadMap(docMap);
+
+ emit updateGUI();
+}
+
void TDEFileReplaceView::slotStringsSave()
{
// Check there are strings in the list
@@ -435,7 +511,7 @@ void TDEFileReplaceView::slotStringsSave()
// Selects the file where strings will be saved
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, this, i18n("Save Strings to File"));
if (fileName.isEmpty())
return;