You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
7.2 KiB
207 lines
7.2 KiB
/*
|
|
highlightconfig.cpp
|
|
|
|
Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org>
|
|
Copyright (c) 2003 by Matt Rogers <matt@matt.rogers.name>
|
|
|
|
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
|
|
|
|
*************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
*************************************************************************
|
|
*/
|
|
|
|
#include <tqfile.h>
|
|
#include <tqstylesheet.h>
|
|
#include <tqregexp.h>
|
|
#include <tqdir.h>
|
|
#include <tqdom.h>
|
|
|
|
#include <ksavefile.h>
|
|
#include <kstandarddirs.h>
|
|
#include <klocale.h>
|
|
|
|
#include "filter.h"
|
|
#include "highlightconfig.h"
|
|
|
|
|
|
HighlightConfig::HighlightConfig()
|
|
{
|
|
load();
|
|
m_filters.setAutoDelete(true);
|
|
}
|
|
|
|
HighlightConfig::~HighlightConfig()
|
|
{
|
|
m_filters.clear();
|
|
}
|
|
|
|
void HighlightConfig::removeFilter(Filter *f)
|
|
{
|
|
//m_filters is "autodelete (true) so when we use remove(...) it deleted f
|
|
//so don't use (delete (f) after otherwise ot crash
|
|
m_filters.remove(f);
|
|
}
|
|
|
|
void HighlightConfig::appendFilter(Filter *f)
|
|
{
|
|
m_filters.append(f);
|
|
}
|
|
|
|
TQPtrList<Filter> HighlightConfig::filters() const
|
|
{
|
|
return m_filters;
|
|
}
|
|
|
|
Filter* HighlightConfig::newFilter()
|
|
{
|
|
Filter *filtre=new Filter();
|
|
filtre->caseSensitive=false;
|
|
filtre->isRegExp=false;
|
|
filtre->setImportance=false;
|
|
filtre->importance=1;
|
|
filtre->setBG=false;
|
|
filtre->setFG=false;
|
|
filtre->playSound=false;
|
|
filtre->raiseView=false;
|
|
filtre->displayName=i18n("-New filter-");
|
|
m_filters.append(filtre);
|
|
return filtre;
|
|
}
|
|
|
|
void HighlightConfig::load()
|
|
{
|
|
m_filters.clear(); //clear filters
|
|
|
|
TQString filename = locateLocal( "appdata", TQString::tqfromLatin1( "highlight.xml" ) );
|
|
if( filename.isEmpty() )
|
|
return ;
|
|
|
|
TQDomDocument filterList( TQString::tqfromLatin1( "highlight-plugin" ) );
|
|
|
|
TQFile filterListFile( filename );
|
|
filterListFile.open( IO_ReadOnly );
|
|
filterList.setContent( &filterListFile );
|
|
|
|
TQDomElement list = filterList.documentElement();
|
|
|
|
TQDomNode node = list.firstChild();
|
|
while( !node.isNull() )
|
|
{
|
|
TQDomElement element = node.toElement();
|
|
if( !element.isNull() )
|
|
{
|
|
// if( element.tagName() == TQString::tqfromLatin1("filter")
|
|
// {
|
|
Filter *filtre=newFilter();
|
|
TQDomNode filterNode = node.firstChild();
|
|
|
|
while( !filterNode.isNull() )
|
|
{
|
|
TQDomElement filterElement = filterNode.toElement();
|
|
if( !filterElement.isNull() )
|
|
{
|
|
if( filterElement.tagName() == TQString::tqfromLatin1( "display-name" ) )
|
|
{
|
|
filtre->displayName = filterElement.text();
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "search" ) )
|
|
{
|
|
filtre->search = filterElement.text();
|
|
|
|
filtre->caseSensitive= ( filterElement.attribute( TQString::tqfromLatin1( "caseSensitive" ), TQString::tqfromLatin1( "1" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
filtre->isRegExp= ( filterElement.attribute( TQString::tqfromLatin1( "regExp" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "FG" ) )
|
|
{
|
|
filtre->FG = filterElement.text();
|
|
filtre->setFG= ( filterElement.attribute( TQString::tqfromLatin1( "set" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "BG" ) )
|
|
{
|
|
filtre->BG = filterElement.text();
|
|
filtre->setBG= ( filterElement.attribute( TQString::tqfromLatin1( "set" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "importance" ) )
|
|
{
|
|
filtre->importance = filterElement.text().toUInt();
|
|
filtre->setImportance= ( filterElement.attribute( TQString::tqfromLatin1( "set" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "sound" ) )
|
|
{
|
|
filtre->soundFN = filterElement.text();
|
|
filtre->playSound = ( filterElement.attribute( TQString::tqfromLatin1( "set" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
else if( filterElement.tagName() == TQString::tqfromLatin1( "raise" ) )
|
|
{
|
|
filtre->raiseView = ( filterElement.attribute( TQString::tqfromLatin1( "set" ), TQString::tqfromLatin1( "0" ) ) == TQString::tqfromLatin1( "1" ) );
|
|
}
|
|
}
|
|
filterNode = filterNode.nextSibling();
|
|
}
|
|
// }
|
|
}
|
|
node = node.nextSibling();
|
|
}
|
|
filterListFile.close();
|
|
}
|
|
|
|
void HighlightConfig::save()
|
|
{
|
|
|
|
TQString fileName = locateLocal( "appdata", TQString::tqfromLatin1( "highlight.xml" ) );
|
|
|
|
KSaveFile file( fileName );
|
|
if( file.status() == 0 )
|
|
{
|
|
TQTextStream *stream = file.textStream();
|
|
stream->setEncoding( TQTextStream::UnicodeUTF8 );
|
|
|
|
TQString xml = TQString::tqfromLatin1(
|
|
"<?xml version=\"1.0\"?>\n"
|
|
"<!DOCTYPE kopete-highlight-plugin>\n"
|
|
"<highlight-plugin>\n" );
|
|
|
|
// Save metafilter information.
|
|
TQPtrListIterator<Filter> filtreIt( m_filters );
|
|
for( ; filtreIt.current(); ++filtreIt )
|
|
{
|
|
Filter *filtre = *filtreIt;
|
|
xml += TQString::tqfromLatin1( " <filter>\n <display-name>" )
|
|
+ TQStyleSheet::escape(filtre->displayName)
|
|
+ TQString::tqfromLatin1( "</display-name>\n" );
|
|
|
|
xml += TQString::tqfromLatin1(" <search caseSensitive=\"") + TQString::number( static_cast<int>( filtre->caseSensitive ) ) +
|
|
TQString::tqfromLatin1("\" regExp=\"") + TQString::number( static_cast<int>( filtre->isRegExp ) ) +
|
|
TQString::tqfromLatin1( "\">" ) + TQStyleSheet::escape( filtre->search ) + TQString::tqfromLatin1( "</search>\n" );
|
|
|
|
xml += TQString::tqfromLatin1(" <BG set=\"") + TQString::number( static_cast<int>( filtre->setBG ) ) +
|
|
TQString::tqfromLatin1( "\">" ) + TQStyleSheet::escape( filtre->BG.name() ) + TQString::tqfromLatin1( "</BG>\n" );
|
|
xml += TQString::tqfromLatin1(" <FG set=\"") + TQString::number( static_cast<int>( filtre->setFG ) ) +
|
|
TQString::tqfromLatin1( "\">" ) + TQStyleSheet::escape( filtre->FG.name() ) + TQString::tqfromLatin1( "</FG>\n" );
|
|
|
|
xml += TQString::tqfromLatin1(" <importance set=\"") + TQString::number( static_cast<int>( filtre->setImportance ) ) +
|
|
TQString::tqfromLatin1( "\">" ) + TQString::number( filtre->importance ) + TQString::tqfromLatin1( "</importance>\n" );
|
|
|
|
xml += TQString::tqfromLatin1(" <sound set=\"") + TQString::number( static_cast<int>( filtre->playSound ) ) +
|
|
TQString::tqfromLatin1( "\">" ) + TQStyleSheet::escape( filtre->soundFN ) + TQString::tqfromLatin1( "</sound>\n" );
|
|
|
|
xml += TQString::tqfromLatin1(" <raise set=\"") + TQString::number( static_cast<int>( filtre->raiseView ) ) +
|
|
TQString::tqfromLatin1( "\"></raise>\n" );
|
|
|
|
xml += TQString::tqfromLatin1( " </filter>\n" );
|
|
}
|
|
|
|
xml += TQString::tqfromLatin1( "</highlight-plugin>\n" );
|
|
|
|
*stream << xml;
|
|
}
|
|
}
|
|
|
|
// vim: set noet ts=4 sts=4 sw=4:
|