summaryrefslogtreecommitdiffstats
path: root/tdefilereplace/tdefilereplaceview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdefilereplace/tdefilereplaceview.cpp')
-rw-r--r--tdefilereplace/tdefilereplaceview.cpp655
1 files changed, 429 insertions, 226 deletions
diff --git a/tdefilereplace/tdefilereplaceview.cpp b/tdefilereplace/tdefilereplaceview.cpp
index 4bf7319..5861eb1 100644
--- a/tdefilereplace/tdefilereplaceview.cpp
+++ b/tdefilereplace/tdefilereplaceview.cpp
@@ -2,7 +2,7 @@
tdefilereplaceview.cpp - description
-------------------
begin : sam oct 16 15:28:00 CEST 1999
- copyright : (C) 1999 by Fran�is Dupoux <dupoux@dupoux.com>
+ copyright : (C) 1999 by François Dupoux <dupoux@dupoux.com>
(C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it>
*****************************************************************************/
@@ -19,6 +19,7 @@
#include <tqwhatsthis.h>
#include <tqmap.h>
#include <tqfileinfo.h>
+#include <tqdom.h>
// KDE
#include <tdelistview.h>
@@ -51,40 +52,46 @@ TDEFileReplaceView::TDEFileReplaceView(RCOptions* info, TQWidget *parent,const c
initGUI();
// result listview: connect events
- connect(m_lvResults, TQT_SIGNAL(mouseButtonClicked(int, TQListViewItem *, const TQPoint &, int)),
- this, TQT_SLOT(slotResultMouseButtonClicked(int, TQListViewItem *, const TQPoint &)));
- connect(m_lvResults, TQT_SIGNAL(returnPressed(TQListViewItem *)),
- this, TQT_SLOT(slotResultReturnPressed(TQListViewItem *)));
- connect(m_lvResults, TQT_SIGNAL(executed(TQListViewItem *)),
- this, TQT_SLOT(slotResultReturnPressed(TQListViewItem *)));
- connect(m_lvResults_2, TQT_SIGNAL(mouseButtonClicked(int, TQListViewItem *, const TQPoint &, int)),
- this, TQT_SLOT(slotResultMouseButtonClicked(int, TQListViewItem *, const TQPoint &)));
- connect(m_lvResults_2, TQT_SIGNAL(returnPressed(TQListViewItem *)),
- this, TQT_SLOT(slotResultReturnPressed(TQListViewItem *)));
- connect(m_lvResults_2, TQT_SIGNAL(executed(TQListViewItem *)),
- this, TQT_SLOT(slotResultReturnPressed(TQListViewItem *)));
+ connect(m_lvResults, TQ_SIGNAL(mouseButtonClicked(int, TQListViewItem *, const TQPoint &, int)),
+ this, TQ_SLOT(slotResultMouseButtonClicked(int, TQListViewItem *, const TQPoint &)));
+ connect(m_lvResults, TQ_SIGNAL(returnPressed(TQListViewItem *)),
+ this, TQ_SLOT(slotResultReturnPressed(TQListViewItem *)));
+ connect(m_lvResults, TQ_SIGNAL(executed(TQListViewItem *)),
+ this, TQ_SLOT(slotResultReturnPressed(TQListViewItem *)));
+ connect(m_lvResults_2, TQ_SIGNAL(mouseButtonClicked(int, TQListViewItem *, const TQPoint &, int)),
+ this, TQ_SLOT(slotResultMouseButtonClicked(int, TQListViewItem *, const TQPoint &)));
+ connect(m_lvResults_2, TQ_SIGNAL(returnPressed(TQListViewItem *)),
+ this, TQ_SLOT(slotResultReturnPressed(TQListViewItem *)));
+ connect(m_lvResults_2, TQ_SIGNAL(executed(TQListViewItem *)),
+ this, TQ_SLOT(slotResultReturnPressed(TQListViewItem *)));
// connect header events
- connect(m_lvResults->header(), TQT_SIGNAL(clicked(int)), this,TQT_SLOT(slotResultHeaderClicked(int)));
- connect(m_lvResults_2->header(), TQT_SIGNAL(clicked(int)), this,TQT_SLOT(slotResultHeaderClicked(int)));
+ connect(m_lvResults->header(), TQ_SIGNAL(clicked(int)), this,TQ_SLOT(slotResultHeaderClicked(int)));
+ connect(m_lvResults_2->header(), TQ_SIGNAL(clicked(int)), this,TQ_SLOT(slotResultHeaderClicked(int)));
// string listview: connect events
- connect(m_lvStrings, TQT_SIGNAL(doubleClicked(TQListViewItem *)), this, TQT_SLOT(slotStringsEdit()));
- connect(m_lvStrings_2, TQT_SIGNAL(doubleClicked(TQListViewItem *)), this, TQT_SLOT(slotStringsEdit()));
+ connect(m_lvStrings, TQ_SIGNAL(doubleClicked(TQListViewItem *)), this, TQ_SLOT(slotStringsAdd()));
+ connect(m_lvStrings_2, TQ_SIGNAL(doubleClicked(TQListViewItem *)), this, TQ_SLOT(slotStringsAdd()));
whatsThis();
}
-TQString TDEFileReplaceView::currentPath()
+TQString TDEFileReplaceView::getItemPath(const TQListViewItem *lvi)
{
- TQListViewItem *lvi;
-
- if(! m_lviCurrent) lvi = m_rv->currentItem();
- else lvi = (TQListViewItem*) m_lviCurrent;
+ if (!lvi)
+ {
+ return TQString::null;
+ }
+ return TQString(lvi->text(1)+"/"+lvi->text(0));
+}
- while (lvi->parent())
+TQListViewItem* TDEFileReplaceView::getCurrItemTopLevelParent()
+{
+ TQListViewItem *lvi = m_rv->currentItem();
+ while (lvi && lvi->parent())
+ {
lvi = lvi->parent();
-
- return TQString(lvi->text(1)+"/"+lvi->text(0));
+ }
+ return lvi;
}
void TDEFileReplaceView::showSemaphore(TQString s)
@@ -119,61 +126,78 @@ void TDEFileReplaceView::displayScannedFiles(int foldersNumber, int filesNumber)
void TDEFileReplaceView::stringsInvert(bool invertAll)
{
- TQListViewItem* lviCurItem,
- * lviFirst;
- TDEListView* sv = getStringsView();
+ if (m_option->m_searchingOnlyMode)
+ {
+ return;
+ }
- if(invertAll)
- lviCurItem = lviFirst = sv->firstChild();
+ TDEListView *sv = getStringsView();
+ TQListViewItem *lviCurItem;
+ if (invertAll)
+ {
+ lviCurItem = sv->firstChild();
+ }
else
- lviCurItem = lviFirst = sv->currentItem();
-
- if(lviCurItem == 0)
- return ;
+ {
+ lviCurItem = sv->currentItem();
+ }
+ if (!lviCurItem)
+ {
+ return;
+ }
do
{
- TQString searchText = lviCurItem->text(0),
- replaceText = lviCurItem->text(1);
+ TQString searchText = lviCurItem->text(0), replaceText = lviCurItem->text(1);
- // Cannot invert the string when search string is empty
+ // Cannot invert the string when search string is empty
if (replaceText.isEmpty())
{
- KMessageBox::error(0, i18n("<qt>Cannot invert string <b>%1</b>, because the search string would be empty.</qt>").arg(searchText));
- return;
+ KMessageBox::error(0, i18n("<qt>Cannot invert string <b>%1</b>, because the search string would be empty.</qt>")
+ .arg(searchText));
}
+ else
+ {
+ lviCurItem->setText(0, replaceText);
+ lviCurItem->setText(1, searchText);
+ }
+ lviCurItem = lviCurItem->nextSibling();
+ } while (invertAll && lviCurItem);
- lviCurItem->setText(0, replaceText);
- lviCurItem->setText(1, searchText);
+ updateStringMap();
+ emit updateGUI();
+}
- lviCurItem = lviCurItem->nextSibling();
- if(!invertAll)
- break;
- } while(lviCurItem && lviCurItem != lviFirst);
- setCurrentStringsViewMap();
+void TDEFileReplaceView::changeViews()
+{
+ changeViews(m_option->m_searchingOnlyMode);
}
-void TDEFileReplaceView::changeView(bool searchingOnlyMode)
+void TDEFileReplaceView::changeViews(bool searchingOnlyMode)
{
- if(searchingOnlyMode)
- {
- m_stackResults->raiseWidget(m_lvResults_2);
- m_stackStrings->raiseWidget(m_lvStrings_2);
- m_rv = m_lvResults_2;
- m_sv = m_lvStrings_2;
- }
+ if (searchingOnlyMode)
+ {
+ m_stackResults->raiseWidget(m_lvResults_2);
+ m_stackStrings->raiseWidget(m_lvStrings_2);
+ m_rv = m_lvResults_2;
+ m_sv = m_lvStrings_2;
+ m_lvResults->clear();
+ m_lvStrings->clear();
+ }
else
- {
- m_stackResults->raiseWidget(m_lvResults);
- m_stackStrings->raiseWidget(m_lvStrings);
- m_rv = m_lvResults;
- m_sv = m_lvStrings;
- }
+ {
+ m_stackResults->raiseWidget(m_lvResults);
+ m_stackStrings->raiseWidget(m_lvStrings);
+ m_rv = m_lvResults;
+ m_sv = m_lvStrings;
+ m_lvResults_2->clear();
+ m_lvStrings_2->clear();
+ }
}
TDEListView* TDEFileReplaceView::getResultsView()
{
- if(m_option->m_searchingOnlyMode)
+ if (m_option->m_searchingOnlyMode)
m_rv = m_lvResults_2;
else
m_rv = m_lvResults;
@@ -183,7 +207,7 @@ TDEListView* TDEFileReplaceView::getResultsView()
TDEListView* TDEFileReplaceView::getStringsView()
{
- if(m_option->m_searchingOnlyMode)
+ if (m_option->m_searchingOnlyMode)
m_sv = m_lvStrings_2;
else
m_sv = m_lvStrings;
@@ -196,10 +220,9 @@ void TDEFileReplaceView::slotResultMouseButtonClicked(int button, TQListViewItem
if (lvi == 0) // No item selected
return;
- if (button == Qt::RightButton)
+ if (button == TQt::RightButton)
{
// Right mouse button: open popup menub
- m_lviCurrent = static_cast<TDEListViewItem*>(lvi);
m_menuResult->popup(pos);
}
}
@@ -210,52 +233,47 @@ void TDEFileReplaceView::slotResultReturnPressed (TQListViewItem *lvi)
return;
// Left mouse button: open item in default view
- m_lviCurrent = static_cast<TDEListViewItem*>(lvi);
slotResultOpen();
}
void TDEFileReplaceView::slotResultProperties()
{
- TQString currItem = currentPath();
- if(! currItem.isEmpty())
- {
- KURL url(currItem);
- (void) new KPropertiesDialog(url);
- m_lviCurrent = 0;
- }
+ TQString currItemPath = getItemPath(getCurrItemTopLevelParent());
+ if (!currItemPath.isEmpty())
+ {
+ KURL url(currItemPath);
+ (void) new KPropertiesDialog(url);
+ }
}
void TDEFileReplaceView::slotResultOpen()
{
- TQString currItem = currentPath();
- if(!currItem.isEmpty())
- {
- (void) new KRun(KURL(currItem), 0, true, true);
- m_lviCurrent = 0;
- }
+ TQString currItemPath = getItemPath(getCurrItemTopLevelParent());
+ if (!currItemPath.isEmpty())
+ {
+ (void) new KRun(KURL(currItemPath), 0, true, true);
+ }
}
void TDEFileReplaceView::slotResultOpenWith()
{
- TQString currItem = currentPath();
- if(!currItem.isEmpty())
- {
- KURL::List kurls;
- kurls.append(KURL(currItem));
- KRun::displayOpenWithDialog(kurls);
- m_lviCurrent = 0;
- }
+ TQString currItemPath = getItemPath(getCurrItemTopLevelParent());
+ if (!currItemPath.isEmpty())
+ {
+ KURL::List kurls;
+ kurls.append(KURL(currItemPath));
+ KRun::displayOpenWithDialog(kurls);
+ }
}
void TDEFileReplaceView::slotResultDirOpen()
{
- TQString currItem = currentPath();
- if(!currItem.isEmpty())
+ TQString currItemPath = getItemPath(getCurrItemTopLevelParent());
+ if (!currItemPath.isEmpty())
{
TQFileInfo fi;
- fi.setFile(currItem);
+ fi.setFile(currItemPath);
(void) new KRun (KURL::fromPathOrURL(fi.dirPath()), 0, true, true);
- m_lviCurrent = 0;
}
}
@@ -300,28 +318,36 @@ void TDEFileReplaceView::slotResultEdit()
lvi = lvi->nextSibling();
}
+}
- m_lviCurrent = 0;
+void TDEFileReplaceView::slotResultRemoveEntry()
+{
+ TQListViewItem *currItem = getCurrItemTopLevelParent();
+ if (currItem)
+ {
+ delete currItem;
+ }
+ emit updateGUI();
}
void TDEFileReplaceView::slotResultDelete()
{
- TQString currItem = currentPath();
- if (!currItem.isEmpty())
+ TQListViewItem *currItem = getCurrItemTopLevelParent();
+ TQString currItemPath = getItemPath(currItem);
+ if (currItem)
{
TQFile fi;
- int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete %1?").arg(currItem),
+ int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete %1?").arg(currItemPath),
TQString(),KStdGuiItem::del());
if(answer == KMessageBox::Continue)
{
- fi.setName(currItem);
+ fi.setName(currItemPath);
fi.remove();
-
- delete m_lviCurrent;
- m_lviCurrent = 0;
+ delete currItem;
}
}
+ emit updateGUI();
}
void TDEFileReplaceView::slotResultTreeExpand()
@@ -340,6 +366,175 @@ void TDEFileReplaceView::slotResultTreeReduce()
expand(lviRoot, false);
}
+void TDEFileReplaceView::slotResultLoad()
+{
+ // Selects the file to load from
+ TQString menu = "*.tfr_results|" + i18n("TDEFileReplace Results") + " (*.tfr_results)\n*|" + i18n("All Files") + " (*)";
+ TQString fileName = KFileDialog::getOpenFileName(TQString(), menu, this, i18n("Load Results From File"));
+ if (fileName.isEmpty())
+ {
+ return;
+ }
+
+ // Creates a xml document and browses it
+ TQDomDocument doc("results");
+ TQFile file(fileName);
+ if (!file.open(IO_ReadOnly))
+ {
+ KMessageBox::error(this, i18n("<qt>Cannot open the file <b>%1</b> and load the results list.</qt>").arg(fileName));
+ return;
+ }
+
+ if (!doc.setContent(&file))
+ {
+ file.close();
+
+ KMessageBox::information(this, i18n("<qt>File <b>%1</b> seems not to be valid.</qt>").arg(fileName), i18n("Warning"));
+ return;
+ }
+ else
+ {
+ file.close();
+ }
+
+ TQDomElement docElem = doc.documentElement();
+ TQDomNode tln = docElem.firstChild(); // top level node
+ TQString searchAttribute = tln.toElement().attribute("search");
+ if (searchAttribute.isNull() || searchAttribute.isEmpty())
+ {
+ int answer = KMessageBox::warningYesNo(this, i18n("<qt>Missing search type. Is this a search-and-replace list of results?</qt>").arg(fileName),i18n("Warning"),i18n("Yes"),i18n("No"));
+ if (answer == KMessageBox::Yes)
+ {
+ m_option->m_searchingOnlyMode = false;
+ }
+ else
+ {
+ m_option->m_searchingOnlyMode = true;
+ }
+ }
+ else
+ {
+ m_option->m_searchingOnlyMode = (searchAttribute == "true");
+ }
+ changeViews();
+
+ // Clears view
+ TDEListView *rv = getResultsView();
+ rv->clear();
+
+ // Reads the result list
+ KeyValueMap docMap;
+ tln = tln.nextSibling();
+ if (!tln.isNull())
+ {
+ tln = tln.firstChild();
+ }
+ while (!tln.isNull())
+ {
+ TQDomElement fileEle = tln.toElement();
+ if (!fileEle.isNull())
+ {
+ TDEListViewItem *fileItem = new TDEListViewItem(rv);
+ fileItem->setText(0, fileEle.attribute("name", "!ERROR!"));
+ fileItem->setText(1, fileEle.attribute("folder"));
+ if (m_option->m_searchingOnlyMode)
+ {
+ fileItem->setText(2, fileEle.attribute("size"));
+ fileItem->setText(3, fileEle.attribute("matches"));
+ fileItem->setText(4, fileEle.attribute("user"));
+ fileItem->setText(5, fileEle.attribute("group"));
+ }
+ else
+ {
+ fileItem->setText(2, fileEle.attribute("old_size"));
+ fileItem->setText(3, fileEle.attribute("new_size"));
+ fileItem->setText(4, fileEle.attribute("matches"));
+ fileItem->setText(5, fileEle.attribute("user"));
+ fileItem->setText(6, fileEle.attribute("group"));
+ }
+ TQDomNode lineNode = fileEle.firstChild();
+ while (!lineNode.isNull())
+ {
+ TQDomElement lineEle = lineNode.toElement();
+ TDEListViewItem *lineItem = new TDEListViewItem(fileItem);
+ lineItem->setText(0, lineEle.text());
+ lineNode = lineNode.nextSibling();
+ }
+ }
+ tln = tln.nextSibling();
+ }
+
+ emit updateGUI();
+}
+
+void TDEFileReplaceView::slotResultSave()
+{
+ // Check there are results in the list
+ TDEListView *rv = getResultsView();
+ if (!rv->firstChild())
+ {
+ KMessageBox::error(0, i18n("There are no results to save."));
+ return;
+ }
+
+ // Selects the file where results will be saved
+ TQString menu = "*.tfr_results|" + i18n("TDEFileReplace Results") + " (*.tfr_results)\n*|" + i18n("All Files") + " (*)";
+ TQString fileName = KFileDialog::getSaveFileName(TQString(), menu, this, i18n("Save Results to File"));
+ if (fileName.isEmpty())
+ {
+ return;
+ }
+
+ TQFile file(fileName);
+ if (!file.open(IO_WriteOnly))
+ {
+ KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
+ return;
+ }
+ TQTextStream filestream(&file);
+ filestream.setEncoding(TQTextStream::UnicodeUTF8);
+
+ filestream << "<?xml version=\"1.0\" ?>\n<kfr>\n";
+ if (m_option->m_searchingOnlyMode)
+ {
+ filestream << "\t<mode search=\"true\"/>\n";
+ }
+ else
+ {
+ filestream << "\t<mode search=\"false\"/>\n";
+ }
+ filestream << "\t<results>\n";
+
+ TQListViewItem *lvi = rv->firstChild();
+ while (lvi)
+ {
+ // File
+ filestream << TQString("\t\t<file name=\"%1\" folder=\"%2\" ").arg(lvi->text(0)).arg(lvi->text(1));
+ if (m_option->m_searchingOnlyMode)
+ {
+ filestream << TQString("size=\"%1\" matches=\"%2\" user=\"%3\" group=\"%4\">\n")
+ .arg(lvi->text(2)).arg(lvi->text(3)).arg(lvi->text(4)).arg(lvi->text(5));
+ }
+ else
+ {
+ filestream << TQString("old_size=\"%1\" new_size=\"%2\" matches=\"%3\" user=\"%4\" group=\"%5\">\n")
+ .arg(lvi->text(2)).arg(lvi->text(3)).arg(lvi->text(4)).arg(lvi->text(5)).arg(lvi->text(6));
+ }
+ // File entries
+ TQListViewItem *lvsubi = lvi->firstChild();
+ while (lvsubi)
+ {
+ filestream << TQString("\t\t\t<line>%1</line>\n").arg(lvsubi->text(0));
+ lvsubi = lvsubi->nextSibling();
+ }
+ filestream << "\t\t</file>\n";
+ lvi = lvi->nextSibling();
+ }
+
+ filestream << "\t</results>\n</kfr>\n";
+ file.close();
+}
+
void TDEFileReplaceView::slotResultHeaderClicked(int sortCol)
{
TDEListView *lv = getResultsView();
@@ -357,25 +552,14 @@ void TDEFileReplaceView::slotResultHeaderClicked(int sortCol)
void TDEFileReplaceView::slotStringsAdd()
{
- KeyValueMap oldMap(m_option->m_mapStringsView);
-
- KAddStringDlg addStringDlg(m_option, false);
-
+ KAddStringDlg addStringDlg(m_option);
if(!addStringDlg.exec())
+ {
return;
-
- KeyValueMap addedStringsMap(m_option->m_mapStringsView);
- KeyValueMap::Iterator itMap;
-
- for(itMap = oldMap.begin(); itMap != oldMap.end(); ++itMap)
- addedStringsMap.insert(itMap.key(),itMap.data());
-
- m_option->m_mapStringsView = addedStringsMap;
-
- raiseResultsView();
- raiseStringsView();
-
- loadMapIntoView(addedStringsMap);
+ }
+ changeViews();
+ loadMapIntoView(m_option->m_mapStringsView);
+ emit updateGUI();
}
void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace)
@@ -396,125 +580,161 @@ void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const
m_option->m_mapStringsView = map;
- raiseResultsView();
- raiseStringsView();
-
+ changeViews();
loadMapIntoView(map);
}
}
-void TDEFileReplaceView::slotStringsEdit()
+void TDEFileReplaceView::slotStringsLoad()
{
- KeyValueMap oldMap(m_option->m_mapStringsView);
- if(oldMap.isEmpty()) return;
- bool oldSearchFlagValue = m_option->m_searchingOnlyMode;
-
- oldMap.remove(m_sv->currentItem()->text(0));
-
- m_option->m_mapStringsView.clear();
+ // 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;
+ }
- m_option->m_mapStringsView.insert(m_sv->currentItem()->text(0), m_sv->currentItem()->text(1));
+ // Creates a xml document and browses it
+ TQDomDocument doc("strings");
+ TQFile file(fileName);
+ 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;
+ }
- KAddStringDlg addStringDlg(m_option, true);
+ if (!doc.setContent(&file))
+ {
+ file.close();
- if(!addStringDlg.exec())
+ 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;
-
- KeyValueMap newMap(m_option->m_mapStringsView);
- if(oldSearchFlagValue == m_option->m_searchingOnlyMode)
+ }
+ else
{
- KeyValueMap::Iterator itMap;
+ file.close();
+ }
- //merges the two maps
- for(itMap = oldMap.begin(); itMap != oldMap.end(); ++itMap)
- newMap.insert(itMap.key(),itMap.data());
+ TQDomElement docElem = doc.documentElement();
+ TQDomNode n = docElem.firstChild();
+ TQString searchAttribute = n.toElement().attribute("search");
+ 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;
+ }
}
+ else
+ {
+ m_option->m_searchingOnlyMode = (searchAttribute == "true");
+ }
+ changeViews();
- m_option->m_mapStringsView = newMap;
+ // Clears view
+ TDEListView *sv = getStringsView();
+ sv->clear();
- raiseResultsView();
- raiseStringsView();
+ // Reads the string list
+ KeyValueMap docMap;
+ n = n.nextSibling();
+ while (!n.isNull())
+ {
+ TQDomElement e = n.toElement();
+ if (!e.isNull())
+ {
+ TQString searchString = e.firstChild().toElement().text();
+ TQString replaceString = e.lastChild().toElement().text();
+ docMap[searchString] = replaceString;
+ }
+ n = n.nextSibling();
+ }
+ loadMap(docMap);
- loadMapIntoView(newMap);
+ emit updateGUI();
}
void TDEFileReplaceView::slotStringsSave()
{
// Check there are strings in the list
- TDEListView* sv = getStringsView();
-
- if (sv->firstChild() == 0)
+ TDEListView *sv = getStringsView();
+ if (!sv->firstChild())
{
KMessageBox::error(0, i18n("No strings to save as the list is empty."));
+ return;
+ }
+
+ // 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, this, i18n("Save Strings to File"));
+ if (fileName.isEmpty())
+ {
+ return;
+ }
+
+ TQFile file(fileName);
+ if (!file.open(IO_WriteOnly))
+ {
+ KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
return ;
}
- TQString header("<?xml version=\"1.0\" ?>\n<kfr>"),
- footer("\n</kfr>"),
- body;
+ TQString header("<?xml version=\"1.0\" ?>\n<kfr>"), footer("\n</kfr>"), body;
if(m_option->m_searchingOnlyMode)
header += "\n\t<mode search=\"true\"/>";
else
header += "\n\t<mode search=\"false\"/>";
- TQListViewItem* lvi = sv->firstChild();
-
- while( lvi )
+ TQListViewItem *lvi = sv->firstChild();
+ while (lvi)
{
body += TQString("\n\t<replacement>"
- "\n\t\t<oldstring><![CDATA[%1]]></oldstring>"
- "\n\t\t<newstring><![CDATA[%2]]></newstring>"
- "\n\t</replacement>").arg(lvi->text(0)).arg(lvi->text(1));
+ "\n\t\t<oldstring>%1</oldstring>"
+ "\n\t\t<newstring>%2</newstring>"
+ "\n\t</replacement>").arg(lvi->text(0)).arg(lvi->text(1));
lvi = lvi->nextSibling();
}
- // 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"));
- if (fileName.isEmpty())
- return;
-
- // Forces the extension to be "kfr" == TDEFileReplace extension
-
- fileName = TDEFileReplaceLib::addExtension(fileName, "kfr");
-
- TQFile file( fileName );
- if(!file.open( IO_WriteOnly ))
- {
- KMessageBox::error(0, i18n("File %1 cannot be saved.").arg(fileName));
- return ;
- }
- TQTextStream oTStream( &file );
+ TQTextStream oTStream(&file);
oTStream.setEncoding(TQTextStream::UnicodeUTF8);
- oTStream << header
- << body
- << footer;
+ oTStream << header << body << footer;
file.close();
}
+void TDEFileReplaceView::slotStringsInvertCur()
+{
+ stringsInvert(false);
+}
+
+void TDEFileReplaceView::slotStringsInvertAll()
+{
+ stringsInvert(true);
+}
+
void TDEFileReplaceView::slotStringsDeleteItem()
{
- TQListViewItem* item = m_sv->currentItem();
- if(item != 0)
+ TQListViewItem *item = m_sv->currentItem();
+ if (item)
{
KeyValueMap m = m_option->m_mapStringsView;
m.remove(item->text(0));
m_option->m_mapStringsView = m;
delete item;
+ emit updateGUI();
}
}
void TDEFileReplaceView::slotStringsEmpty()
{
- TQListViewItem * myChild = m_sv->firstChild();
- while( myChild )
- {
- TQListViewItem* item = myChild;
- myChild = myChild->nextSibling();
- delete item;
- }
- KeyValueMap m;
- m_option->m_mapStringsView = m;
+ m_sv->clear();
+ m_option->m_mapStringsView.clear();
+ emit updateGUI();
}
//PRIVATE
@@ -548,57 +768,38 @@ void TDEFileReplaceView::initGUI()
m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("document-open")),
i18n("&Open"),
this,
- TQT_SLOT(slotResultOpen()));
- if(!quantaFound)
- {
- m_menuResult->insertItem(i18n("Open &With..."),
- this,
- TQT_SLOT(slotResultOpenWith()));
- }
+ TQ_SLOT(slotResultOpen()));
+ m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("document-open")),
+ i18n("Open &With..."),
+ this,
+ TQ_SLOT(slotResultOpenWith()));
if(quantaFound)
{
m_menuResult->insertItem(SmallIconSet("quanta"),
i18n("&Edit in Quanta"),
this,
- TQT_SLOT(slotResultEdit()));
+ TQ_SLOT(slotResultEdit()));
}
m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("go-up")),
i18n("Open Parent &Folder"),
this,
- TQT_SLOT(slotResultDirOpen()));
+ TQ_SLOT(slotResultDirOpen()));
+ m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("edit-clear")),
+ i18n("Remove &Entry"),
+ this,
+ TQ_SLOT(slotResultRemoveEntry()));
m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("edit-delete")),
i18n("&Delete"),
this,
- TQT_SLOT(slotResultDelete()));
+ TQ_SLOT(slotResultDelete()));
m_menuResult->insertSeparator();
m_menuResult->insertItem(SmallIconSet(TQString::fromLatin1("application-vnd.tde.info")),
i18n("&Properties"),
this,
- TQT_SLOT(slotResultProperties()));
- raiseResultsView();
- raiseStringsView();
-}
-
-void TDEFileReplaceView::raiseStringsView()
-{
- if(m_option->m_searchingOnlyMode)
- m_sv = m_lvStrings_2;
- else
- m_sv = m_lvStrings;
-
- m_stackStrings->raiseWidget(m_sv);
-}
-
-void TDEFileReplaceView::raiseResultsView()
-{
- if(m_option->m_searchingOnlyMode)
- m_rv = m_lvResults_2;
- else
- m_rv = m_lvResults;
-
- m_stackResults->raiseWidget(m_rv);
+ TQ_SLOT(slotResultProperties()));
+ changeViews();
}
coord TDEFileReplaceView::extractWordCoordinates(TQListViewItem* lvi)
@@ -680,26 +881,28 @@ void TDEFileReplaceView::expand(TQListViewItem *lviCurrent, bool b)
}
}
-void TDEFileReplaceView::setMap()
+void TDEFileReplaceView::updateStringMap()
{
- KeyValueMap map;
- TQListViewItem* i = m_sv->firstChild();
- while(i != 0)
+ m_option->m_mapStringsView.clear();
+ TQListViewItem *item = m_sv->firstChild();
+ while (item)
{
- if(m_option->m_searchingOnlyMode)
- map[i->text(0)] = TQString();
+ if (m_option->m_searchingOnlyMode)
+ {
+ m_option->m_mapStringsView[item->text(0)] = TQString();
+ }
else
- map[i->text(0)] = i->text(1);
- i = i->nextSibling();
+ {
+ m_option->m_mapStringsView[item->text(0)] = item->text(1);
+ }
+ item = item->nextSibling();
}
- m_option->m_mapStringsView = map;
}
void TDEFileReplaceView::loadMapIntoView(KeyValueMap map)
{
m_sv->clear();
KeyValueMap::Iterator itMap;
-
for(itMap = map.begin(); itMap != map.end(); ++itMap)
{
TQListViewItem* lvi = new TQListViewItem(m_sv);