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 <michele.calgaro@yahoo.it>
pull/11/head
Michele Calgaro 5 years ago
parent c722431cbb
commit 10db438b9a
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -83,8 +83,6 @@ RCOptions& RCOptions::operator=(const RCOptions& ci)
m_quickSearchString = ci.m_quickSearchString; m_quickSearchString = ci.m_quickSearchString;
m_quickReplaceString = ci.m_quickReplaceString; m_quickReplaceString = ci.m_quickReplaceString;
m_recentStringFileList = ci.m_recentStringFileList;
m_notifyOnErrors = ci.m_notifyOnErrors; m_notifyOnErrors = ci.m_notifyOnErrors;
return (*this); return (*this);

@ -30,7 +30,6 @@ const TQString rcSearchStringsList = "Search strings list";
const TQString rcReplaceStringsList = "Replace strings list"; const TQString rcReplaceStringsList = "Replace strings list";
const TQString rcDirectoriesList = "Directories list"; const TQString rcDirectoriesList = "Directories list";
const TQString rcFiltersList = "Filters list"; const TQString rcFiltersList = "Filters list";
const TQString rcRecentFiles = "Recent files";
const TQString rcAllStringsMustBeFound = "All strings must be found"; const TQString rcAllStringsMustBeFound = "All strings must be found";
const TQString rcEncoding = "Encoding"; const TQString rcEncoding = "Encoding";
const TQString rcCaseSensitive = "Case sensitive"; const TQString rcCaseSensitive = "Case sensitive";
@ -138,8 +137,6 @@ class RCOptions
TQString m_quickSearchString, TQString m_quickSearchString,
m_quickReplaceString; m_quickReplaceString;
TQStringList m_recentStringFileList;
bool m_notifyOnErrors; bool m_notifyOnErrors;
public: public:

@ -3,7 +3,7 @@
------------------- -------------------
begin : lun mai 3 20:19:52 CEST 1999 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 <amantia@kde.org> (C) 2003 Andras Mantia <amantia@kde.org>
(C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it> (C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it>
email : dupoux@dupoux.com email : dupoux@dupoux.com
@ -119,82 +119,6 @@ TQString TDEFileReplaceLib::formatFileSize(double size)
return stringSize; 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) bool TDEFileReplaceLib::isAnAccessibleFile(const TQString& filePath, const TQString& fileName, RCOptions* info)
{ {
TQString bkExt = info->m_backupExtension; TQString bkExt = info->m_backupExtension;

@ -3,7 +3,7 @@
------------------- -------------------
begin : lun mai 3 20:19:52 CEST 1999 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 <amantia@kde.org> (C) 2003 Andras Mantia <amantia@kde.org>
(C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it> (C) 2004 Emiliano Gulmini <emi_barbarossa@yahoo.it>
email : dupoux@dupoux.com email : dupoux@dupoux.com
@ -50,10 +50,6 @@ class TDEFileReplaceLib
static TQString formatFileSize(double size); 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 Verifies that files, which we are scanning, respect some
conditions conditions

@ -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() void TDEFileReplacePart::slotOptionRecursive()
{ {
m_option->m_recursive = !m_option->m_recursive; 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("&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("&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("&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 TDEAction(i18n("&Load Strings List From File..."), "unsortedList", 0, TQT_TQOBJECT(m_view), 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("&Invert Current String (search <--> replace)"), "invert", 0, TQT_TQOBJECT(m_view), TQT_SLOT(slotStringsInvertCur()), actionCollection(), "strings_invert"); (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"); (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_config->setGroup("General Options");
m_option->m_recentStringFileList = m_config->readListEntry(rcRecentFiles);
m_option->m_searchingOnlyMode = m_config->readBoolEntry(rcSearchMode,SearchModeOption); m_option->m_searchingOnlyMode = m_config->readBoolEntry(rcSearchMode,SearchModeOption);
m_config->setGroup("Options"); m_config->setGroup("Options");
@ -793,7 +757,6 @@ void TDEFileReplacePart::saveOptions()
{ {
m_config->setGroup("General Options"); m_config->setGroup("General Options");
m_config->writeEntry(rcRecentFiles, m_option->m_recentStringFileList);
m_config->writeEntry(rcSearchMode,m_option->m_searchingOnlyMode); m_config->writeEntry(rcSearchMode,m_option->m_searchingOnlyMode);
m_config->setGroup("Options"); m_config->setGroup("Options");
@ -1525,89 +1488,6 @@ void TDEFileReplacePart::loadViewContent()
m_replacementMap = tempMap; 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) bool TDEFileReplacePart::launchNewProjectDialog(const KURL & startURL)
{ {
if(!startURL.isEmpty()) if(!startURL.isEmpty())

@ -64,8 +64,6 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
void slotStop(); void slotStop();
void slotCreateReport(); void slotCreateReport();
void slotQuickStringsAdd(); void slotQuickStringsAdd();
void slotStringsLoad();
void slotOpenRecentStringFile(const KURL& urlFile);
void slotOptionRecursive(); void slotOptionRecursive();
void slotOptionBackup(); void slotOptionBackup();
void slotOptionCaseSensitive(); void slotOptionCaseSensitive();
@ -145,7 +143,6 @@ class TDEFileReplacePart: public KParts::ReadOnlyPart
* Others methods * Others methods
*/ */
void loadViewContent(); void loadViewContent();
void loadRulesFile(const TQString& fileName);
bool launchNewProjectDialog(const KURL& startURL); bool launchNewProjectDialog(const KURL& startURL);
void setOptionMask(); void setOptionMask();
bool checkBeforeOperation(); bool checkBeforeOperation();

@ -15,7 +15,6 @@
<Separator/> <Separator/>
<Action name="strings_save"/> <Action name="strings_save"/>
<Action name="strings_load"/> <Action name="strings_load"/>
<Action name="strings_load_recent"/>
<Separator/> <Separator/>
<Action name="strings_invert"/> <Action name="strings_invert"/>
<Action name="strings_invert_all"/> <Action name="strings_invert_all"/>

@ -19,6 +19,7 @@
#include <tqwhatsthis.h> #include <tqwhatsthis.h>
#include <tqmap.h> #include <tqmap.h>
#include <tqfileinfo.h> #include <tqfileinfo.h>
#include <tqdom.h>
// KDE // KDE
#include <tdelistview.h> #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() void TDEFileReplaceView::slotStringsSave()
{ {
// Check there are strings in the list // Check there are strings in the list
@ -435,7 +511,7 @@ void TDEFileReplaceView::slotStringsSave()
// 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, this, i18n("Save Strings to File"));
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;

@ -92,6 +92,7 @@ class TDEFileReplaceView : public TDEFileReplaceViewWdg
void slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace); void slotQuickStringsAdd(const TQString& quickSearch, const TQString& quickReplace);
void slotStringsDeleteItem(); void slotStringsDeleteItem();
void slotStringsEmpty(); void slotStringsEmpty();
void slotStringsLoad();
void slotStringsSave(); void slotStringsSave();
void slotStringsInvertCur(); void slotStringsInvertCur();
void slotStringsInvertAll(); void slotStringsInvertAll();

Loading…
Cancel
Save