summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2019-06-21 23:01:51 +0900
committerMichele Calgaro <[email protected]>2019-06-21 23:01:51 +0900
commit10db438b9a5b758a384d4c007e88f1cda2981cc8 (patch)
tree0ea1dcecb2f18ce4d77ec5081dad16e8b76fb654
parentc722431cbb37b120038bd2d0731e7ef74cce9d75 (diff)
downloadtdeutils-10db438b9a5b758a384d4c007e88f1cda2981cc8.tar.gz
tdeutils-10db438b9a5b758a384d4c007e88f1cda2981cc8.zip
tdefilereplace:
- removed old unused code - removed broken and non functional "recent string files" menu code - moved string load code from part to view, together with the save code. Signed-off-by: Michele Calgaro <[email protected]>
-rw-r--r--tdefilereplace/configurationclasses.cpp2
-rw-r--r--tdefilereplace/configurationclasses.h3
-rw-r--r--tdefilereplace/tdefilereplacelib.cpp78
-rw-r--r--tdefilereplace/tdefilereplacelib.h6
-rw-r--r--tdefilereplace/tdefilereplacepart.cpp122
-rw-r--r--tdefilereplace/tdefilereplacepart.h3
-rw-r--r--tdefilereplace/tdefilereplacepartui.rc1
-rw-r--r--tdefilereplace/tdefilereplaceview.cpp78
-rw-r--r--tdefilereplace/tdefilereplaceview.h1
9 files changed, 81 insertions, 213 deletions
diff --git a/tdefilereplace/configurationclasses.cpp b/tdefilereplace/configurationclasses.cpp
index afc3d85..964226b 100644
--- a/tdefilereplace/configurationclasses.cpp
+++ b/tdefilereplace/configurationclasses.cpp
@@ -83,8 +83,6 @@ RCOptions& RCOptions::operator=(const RCOptions& ci)
m_quickSearchString = ci.m_quickSearchString;
m_quickReplaceString = ci.m_quickReplaceString;
- m_recentStringFileList = ci.m_recentStringFileList;
-
m_notifyOnErrors = ci.m_notifyOnErrors;
return (*this);
diff --git a/tdefilereplace/configurationclasses.h b/tdefilereplace/configurationclasses.h
index beaa275..41b0ba9 100644
--- a/tdefilereplace/configurationclasses.h
+++ b/tdefilereplace/configurationclasses.h
@@ -30,7 +30,6 @@ const TQString rcSearchStringsList = "Search strings list";
const TQString rcReplaceStringsList = "Replace strings list";
const TQString rcDirectoriesList = "Directories list";
const TQString rcFiltersList = "Filters list";
-const TQString rcRecentFiles = "Recent files";
const TQString rcAllStringsMustBeFound = "All strings must be found";
const TQString rcEncoding = "Encoding";
const TQString rcCaseSensitive = "Case sensitive";
@@ -138,8 +137,6 @@ class RCOptions
TQString m_quickSearchString,
m_quickReplaceString;
- TQStringList m_recentStringFileList;
-
bool m_notifyOnErrors;
public:
diff --git a/tdefilereplace/tdefilereplacelib.cpp b/tdefilereplace/tdefilereplacelib.cpp
index cf9b578..4246fc8 100644
--- a/tdefilereplace/tdefilereplacelib.cpp
+++ b/tdefilereplace/tdefilereplacelib.cpp
@@ -3,7 +3,7 @@
-------------------
begin : lun mai 3 20:19:52 CEST 1999
- copyright : (C) 1999 by Fran�ois Dupoux
+ copyright : (C) 1999 by François Dupoux
(C) 2003 Andras Mantia <[email protected]>
(C) 2004 Emiliano Gulmini <[email protected]>
@@ -119,82 +119,6 @@ TQString TDEFileReplaceLib::formatFileSize(double size)
return stringSize;
}
-void TDEFileReplaceLib::convertOldToNewKFRFormat(const TQString& fileName, TDEListView* stringView)
-{
- //this method convert old format in new XML-based format
- typedef struct
- {
- char pgm[13]; // Must be "TDEFileReplace" : like MZ for EXE files
- int stringNumber; // Number of strings in file
- char reserved[64]; // Reserved for future use
- } KFRHeader;
-
- KFRHeader head;
-
- FILE* f = fopen(fileName.ascii(),"rb");
- int err = fread(&head, sizeof(KFRHeader), 1, f);
- TQString pgm(head.pgm);
-
- if(!f || (err != 1) || (pgm != "TDEFileReplace"))
- {
- KMessageBox::error(0, i18n("<qt>Cannot open the file <b>%1</b> and load the string list. This file seems not to be a valid old kfr file or it is broken.</qt>").arg(fileName));
- return ;
- }
-
- stringView->clear();
-
- int oldTextSize,
- newTextSize,
- errors = 0,
- stringSize;
- TQStringList l;
-
- int i ;
- for (i=0; i < head.stringNumber; i++)
- {
- errors += (fread(&oldTextSize, sizeof(int), 1, f)) != 1;
- errors += (fread(&newTextSize, sizeof(int), 1, f)) != 1;
- if(errors > 0)
- KMessageBox::error(0, i18n("Cannot read data."));
- else
- {
- stringSize = ((oldTextSize > newTextSize) ? oldTextSize : newTextSize) + 2;
- char* oldString = (char*) malloc(stringSize+10),
- * newString = (char*) malloc(stringSize+10);
- memset(oldString, 0, stringSize);
- memset(newString,0, stringSize);
- if (oldString == 0 || newString == 0)
- KMessageBox::error(0, i18n("Out of memory."));
- else
- {
- if (fread(oldString, oldTextSize, 1, f) != 1)
- KMessageBox::error(0, i18n("Cannot read data."));
- else
- {
- if (newTextSize > 0) // If there is a Replace text
- {
- if (fread(newString, newTextSize, 1, f) != 1)
- KMessageBox::error(0, i18n("Cannot read data."));
- else
- {
- TQListViewItem* lvi = new TQListViewItem(stringView);
- lvi->setText(0,oldString);
- lvi->setText(1,newString);
-
- if(newString)
- free(newString);
- if(oldString)
- free(oldString);
- }
- }
- }
- }
- }
- }
- fclose(f);
- return ;
- }
-
bool TDEFileReplaceLib::isAnAccessibleFile(const TQString& filePath, const TQString& fileName, RCOptions* info)
{
TQString bkExt = info->m_backupExtension;
diff --git a/tdefilereplace/tdefilereplacelib.h b/tdefilereplace/tdefilereplacelib.h
index d04f8a3..b0273ac 100644
--- a/tdefilereplace/tdefilereplacelib.h
+++ b/tdefilereplace/tdefilereplacelib.h
@@ -3,7 +3,7 @@
-------------------
begin : lun mai 3 20:19:52 CEST 1999
- copyright : (C) 1999 by Fran�ois Dupoux
+ copyright : (C) 1999 by François Dupoux
(C) 2003 Andras Mantia <[email protected]>
(C) 2004 Emiliano Gulmini <[email protected]>
@@ -51,10 +51,6 @@ class TDEFileReplaceLib
static TQString formatFileSize(double size);
/**
- converts the old kfr format file in the new xml-based format.
- */
- static void convertOldToNewKFRFormat(const TQString& fileName, TDEListView* stringView);
- /**
Verifies that files, which we are scanning, respect some
conditions
*/
diff --git a/tdefilereplace/tdefilereplacepart.cpp b/tdefilereplace/tdefilereplacepart.cpp
index d562437..766366f 100644
--- a/tdefilereplace/tdefilereplacepart.cpp
+++ b/tdefilereplace/tdefilereplacepart.cpp
@@ -322,39 +322,6 @@ void TDEFileReplacePart::slotQuickStringsAdd()
}
}
-void TDEFileReplacePart::slotStringsLoad()
-{
- // Selects the file to load from
- TQString menu = "*.kfr|" + i18n("TDEFileReplace strings") + " (*.kfr)\n*|"+i18n("All Files") + " (*)";
- TQString fileName = KFileDialog::getOpenFileName(TQString(), menu, m_w, i18n("Load Strings From File"));
-
- if(!fileName.isEmpty())
- loadRulesFile(fileName);
-
- updateGUI();
-}
-
-void TDEFileReplacePart::slotOpenRecentStringFile(const KURL& urlFile)
-{
- TQString fileName;
-
- // Downloads file if need (if url is "http://...")
- if (!(TDEIO::NetAccess::download(urlFile, fileName, 0)))
- return;
-
- // Checks it's not a directory
- TQFileInfo fileInfo;
- fileInfo.setFile(fileName);
- if(fileInfo.isDir())
- {
- KMessageBox::error(m_w, i18n("Cannot open folders."));
- return;
- }
-
- loadRulesFile(fileName);
- updateGUI();
-}
-
void TDEFileReplacePart::slotOptionRecursive()
{
m_option->m_recursive = !m_option->m_recursive;
@@ -553,8 +520,7 @@ void TDEFileReplacePart::initGUI()
(void)new TDEAction(i18n("&Delete String"), "editremove", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsDeleteItem()), actionCollection(), "strings_del");
(void)new TDEAction(i18n("&Empty Strings List"), "edit-delete", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsEmpty()), actionCollection(), "strings_empty");
(void)new TDEAction(i18n("&Save Strings List to File..."), "document-save-as", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsSave()), actionCollection(), "strings_save");
- (void)new TDEAction(i18n("&Load Strings List From File..."), "unsortedList", 0, TQT_TQOBJECT(this), TQT_SLOT(slotStringsLoad()), actionCollection(), "strings_load");
- (void)new TDERecentFilesAction(i18n("&Load Recent Strings Files"), "document-open", 0, TQT_TQOBJECT(this), TQT_SLOT(slotOpenRecentStringFile(const KURL&)), actionCollection(),"strings_load_recent");
+ (void)new TDEAction(i18n("&Load Strings List From File..."), "unsortedList", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsLoad()), actionCollection(), "strings_load");
(void)new TDEAction(i18n("&Invert Current String (search <--> replace)"), "invert", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsInvertCur()), actionCollection(), "strings_invert");
(void)new TDEAction(i18n("&Invert All Strings (search <--> replace)"), "invert", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsInvertAll()), actionCollection(), "strings_invert_all");
@@ -654,8 +620,6 @@ void TDEFileReplacePart::loadOptions()
{
m_config->setGroup("General Options");
- m_option->m_recentStringFileList = m_config->readListEntry(rcRecentFiles);
-
m_option->m_searchingOnlyMode = m_config->readBoolEntry(rcSearchMode,SearchModeOption);
m_config->setGroup("Options");
@@ -793,7 +757,6 @@ void TDEFileReplacePart::saveOptions()
{
m_config->setGroup("General Options");
- m_config->writeEntry(rcRecentFiles, m_option->m_recentStringFileList);
m_config->writeEntry(rcSearchMode,m_option->m_searchingOnlyMode);
m_config->setGroup("Options");
@@ -1525,89 +1488,6 @@ void TDEFileReplacePart::loadViewContent()
m_replacementMap = tempMap;
}
-void TDEFileReplacePart::loadRulesFile(const TQString& fileName)
-{
- // Loads a file with kfr extension, creates a xml document and browses it
- TQDomDocument doc("mydocument");
- TQFile file(fileName);
- TDEListView* sv = m_view->getStringsView();
-
- if(!file.open(IO_ReadOnly))
- {
- KMessageBox::error(m_w, 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(m_w, i18n("<qt>File <b>%1</b> seems not to be written in new kfr format. Remember that the old kfr format will be soon abandoned. You can convert your old rules files by simply saving them with tdefilereplace.</qt>").arg(fileName),i18n("Warning"));
-
- TDEFileReplaceLib::convertOldToNewKFRFormat(fileName, sv);
-
- return;
- }
- else
- file.close();
-
- //clears view
- sv->clear();
-
- TQDomElement docElem = doc.documentElement();
- TQDomNode n = docElem.firstChild();
- TQString searchAttribute = n.toElement().attribute("search").latin1();
-
- KeyValueMap docMap;
-
- if(searchAttribute.isNull() || searchAttribute.isEmpty())
- {
- int answer = KMessageBox::warningYesNo(m_w, i18n("<qt>The format of kfr files has been changed; attempting to load <b>%1</b>. Please see the KFilereplace manual for details. Do you want to load a search-and-replace list of strings?</qt>").arg(fileName),i18n("Warning"),i18n("Load"),i18n("Do Not Load"));
-
- if(answer == KMessageBox::Yes)
- searchAttribute = "false";
- else
- searchAttribute = "true";
- }
- //Verifies the search mode
- if(searchAttribute == "true")
- m_option->m_searchingOnlyMode = true;
- else
- m_option->m_searchingOnlyMode = false;
-
- //Refreshes the view appearances
- m_view->changeView(m_option->m_searchingOnlyMode);
- //Goes to next tag
- n = n.nextSibling();
- //Reads the string list
- while(!n.isNull())
- {
- TQDomElement e = n.toElement(); // tries to convert the node to an element.
- if(!e.isNull())
- {
- TQString oldString = e.firstChild().toElement().text(),
- newString = e.lastChild().toElement().text();
- docMap[oldString] = newString;
- }
- n = n.nextSibling();
- }
-
- // Adds file to "load strings from file" menu
- TQStringList fileList = m_option->m_recentStringFileList;
- if(!fileList.contains(fileName))
- {
- fileList.append(fileName);
- ((TDERecentFilesAction* ) actionCollection()->action("strings_load_recent"))->setItems(fileList);
- m_option->m_recentStringFileList = fileList;
- }
-
- m_view->changeView(m_option->m_searchingOnlyMode);
-
- m_view->loadMap(docMap);
-
- updateGUI();
-}
-
bool TDEFileReplacePart::launchNewProjectDialog(const KURL & startURL)
{
if(!startURL.isEmpty())
diff --git a/tdefilereplace/tdefilereplacepart.h b/tdefilereplace/tdefilereplacepart.h
index e135e05..4495ae9 100644
--- a/tdefilereplace/tdefilereplacepart.h
+++ b/tdefilereplace/tdefilereplacepart.h
@@ -64,8 +64,6 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
void slotStop();
void slotCreateReport();
void slotQuickStringsAdd();
- void slotStringsLoad();
- void slotOpenRecentStringFile(const KURL& urlFile);
void slotOptionRecursive();
void slotOptionBackup();
void slotOptionCaseSensitive();
@@ -145,7 +143,6 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Others methods
*/
void loadViewContent();
- void loadRulesFile(const TQString& fileName);
bool launchNewProjectDialog(const KURL& startURL);
void setOptionMask();
bool checkBeforeOperation();
diff --git a/tdefilereplace/tdefilereplacepartui.rc b/tdefilereplace/tdefilereplacepartui.rc
index ec38719..414fe26 100644
--- a/tdefilereplace/tdefilereplacepartui.rc
+++ b/tdefilereplace/tdefilereplacepartui.rc
@@ -15,7 +15,6 @@
<Separator/>
<Action name="strings_save"/>
<Action name="strings_load"/>
- <Action name="strings_load_recent"/>
<Separator/>
<Action name="strings_invert"/>
<Action name="strings_invert_all"/>
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;
diff --git a/tdefilereplace/tdefilereplaceview.h b/tdefilereplace/tdefilereplaceview.h
index cd30b4d..e763cc5 100644
--- a/tdefilereplace/tdefilereplaceview.h
+++ b/tdefilereplace/tdefilereplaceview.h
@@ -92,6 +92,7 @@ class TDEFileReplaceView : public TDEFileReplaceViewWdg
void slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace);
void slotStringsDeleteItem();
void slotStringsEmpty();
+ void slotStringsLoad();
void slotStringsSave();
void slotStringsInvertCur();
void slotStringsInvertAll();