@ -168,27 +168,36 @@ void TDEFileReplaceView::stringsInvert(bool invertAll)
emit updateGUI ( ) ;
}
void TDEFileReplaceView : : changeView ( bool searchingOnlyMode )
void TDEFileReplaceView : : changeView s ( )
{
if ( searchingOnlyMode )
{
m_stackResults - > raiseWidget ( m_lvResults_2 ) ;
m_stackStrings - > raiseWidget ( m_lvStrings_2 ) ;
m_rv = m_lvResults_2 ;
m_sv = m_lvStrings_2 ;
}
changeViews ( m_option - > m_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 ;
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 ;
@ -198,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 ;
@ -315,9 +324,10 @@ void TDEFileReplaceView::slotResultRemoveEntry()
{
TQListViewItem * currItem = getCurrItemTopLevelParent ( ) ;
if ( currItem )
{
delete currItem ;
}
{
delete currItem ;
}
emit updateGUI ( ) ;
}
void TDEFileReplaceView : : slotResultDelete ( )
@ -337,6 +347,7 @@ void TDEFileReplaceView::slotResultDelete()
delete currItem ;
}
}
emit updateGUI ( ) ;
}
void TDEFileReplaceView : : slotResultTreeExpand ( )
@ -355,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 ( ) ;
@ -377,8 +557,7 @@ void TDEFileReplaceView::slotStringsAdd()
{
return ;
}
raiseResultsView ( ) ;
raiseStringsView ( ) ;
changeViews ( ) ;
loadMapIntoView ( m_option - > m_mapStringsView ) ;
emit updateGUI ( ) ;
}
@ -401,9 +580,7 @@ void TDEFileReplaceView::slotQuickStringsAdd(const TQString& quickSearch, const
m_option - > m_mapStringsView = map ;
raiseResultsView ( ) ;
raiseStringsView ( ) ;
changeViews ( ) ;
loadMapIntoView ( map ) ;
}
}
@ -418,17 +595,16 @@ void TDEFileReplaceView::slotStringsLoad()
return ;
}
// Loads a file with kfr extension, c reates a xml document and browses it
TQDomDocument doc ( " mydocument " ) ;
// C reates a xml document and browses it
TQDomDocument doc ( " strings " ) ;
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 ) )
if ( ! doc . setContent ( & file ) )
{
file . close ( ) ;
@ -440,12 +616,9 @@ void TDEFileReplaceView::slotStringsLoad()
file . close ( ) ;
}
//clears view
sv - > clear ( ) ;
TQDomElement docElem = doc . documentElement ( ) ;
TQDomNode n = docElem . firstChild ( ) ;
TQString searchAttribute = n . toElement ( ) . attribute ( " search " ) .latin1 ( ) ;
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 " ) ) ;
@ -458,16 +631,22 @@ void TDEFileReplaceView::slotStringsLoad()
m_option - > m_searchingOnlyMode = true ;
}
}
else
{
m_option - > m_searchingOnlyMode = ( searchAttribute = = " true " ) ;
}
changeViews ( ) ;
// Refreshes the view appearances
changeView ( m_option - > m_searchingOnlyMode ) ;
// Clears view
TDEListView * sv = getStringsView ( ) ;
sv - > clear ( ) ;
// Reads the string list
KeyValueMap docMap ;
n = n . nextSibling ( ) ;
while ( ! n . isNull ( ) )
{
TQDomElement e = n . toElement ( ) ; // tries to convert the node to an element.
TQDomElement e = n . toElement ( ) ;
if ( ! e . isNull ( ) )
{
TQString searchString = e . firstChild ( ) . toElement ( ) . text ( ) ;
@ -476,8 +655,6 @@ void TDEFileReplaceView::slotStringsLoad()
}
n = n . nextSibling ( ) ;
}
changeView ( m_option - > m_searchingOnlyMode ) ;
loadMap ( docMap ) ;
emit updateGUI ( ) ;
@ -493,6 +670,21 @@ void TDEFileReplaceView::slotStringsSave()
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 ;
if ( m_option - > m_searchingOnlyMode )
header + = " \n \t <mode search= \" true \" /> " ;
@ -509,20 +701,6 @@ void TDEFileReplaceView::slotStringsSave()
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 , this , 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 ) ;
oTStream . setEncoding ( TQTextStream : : UnicodeUTF8 ) ;
oTStream < < header < < body < < footer ;
@ -621,28 +799,7 @@ void TDEFileReplaceView::initGUI()
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 ) ;
changeViews ( ) ;
}
coord TDEFileReplaceView : : extractWordCoordinates ( TQListViewItem * lvi )