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.
230 lines
6.2 KiB
230 lines
6.2 KiB
15 years ago
|
/*
|
||
|
This file is part of the kolab resource - the implementation of the
|
||
|
Kolab storage format. See www.kolab.org for documentation on this.
|
||
|
|
||
|
Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
In addition, as a special exception, the copyright holders give
|
||
|
permission to link the code of this program with any edition of
|
||
14 years ago
|
the TQt library by Trolltech AS, Norway (or with modified versions
|
||
|
of TQt that use the same license as TQt), and distribute linked
|
||
15 years ago
|
combinations including the two. You must obey the GNU General
|
||
|
Public License in all respects for all of the code used other than
|
||
14 years ago
|
TQt. If you modify this file, you may extend this exception to
|
||
15 years ago
|
your version of the file, but you are not obligated to do so. If
|
||
|
you do not wish to do so, delete this exception statement from
|
||
|
your version.
|
||
|
*/
|
||
|
|
||
|
#include "note.h"
|
||
|
|
||
|
#include <libkcal/journal.h>
|
||
|
#include <knotes/version.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
using namespace Kolab;
|
||
|
|
||
|
|
||
15 years ago
|
KCal::Journal* Note::xmlToJournal( const TQString& xml )
|
||
15 years ago
|
{
|
||
|
Note note;
|
||
|
note.load( xml );
|
||
|
KCal::Journal* journal = new KCal::Journal();
|
||
|
note.saveTo( journal );
|
||
|
return journal;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Note::journalToXML( KCal::Journal* journal )
|
||
15 years ago
|
{
|
||
|
Note note( journal );
|
||
|
return note.saveXML();
|
||
|
}
|
||
|
|
||
|
Note::Note( KCal::Journal* journal ) : mRichText( false )
|
||
|
{
|
||
|
if ( journal )
|
||
|
setFields( journal );
|
||
|
}
|
||
|
|
||
|
Note::~Note()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void Note::setSummary( const TQString& summary )
|
||
15 years ago
|
{
|
||
|
mSummary = summary;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Note::summary() const
|
||
15 years ago
|
{
|
||
|
return mSummary;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Note::setBackgroundColor( const TQColor& bgColor )
|
||
15 years ago
|
{
|
||
|
mBackgroundColor = bgColor;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQColor Note::backgroundColor() const
|
||
15 years ago
|
{
|
||
|
return mBackgroundColor;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Note::setForegroundColor( const TQColor& fgColor )
|
||
15 years ago
|
{
|
||
|
mForegroundColor = fgColor;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQColor Note::foregroundColor() const
|
||
15 years ago
|
{
|
||
|
return mForegroundColor;
|
||
|
}
|
||
|
|
||
|
void Note::setRichText( bool richText )
|
||
|
{
|
||
|
mRichText = richText;
|
||
|
}
|
||
|
|
||
|
bool Note::richText() const
|
||
|
{
|
||
|
return mRichText;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool Note::loadAttribute( TQDomElement& element )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString tagName = element.tagName();
|
||
15 years ago
|
if ( tagName == "summary" )
|
||
|
setSummary( element.text() );
|
||
|
else if ( tagName == "foreground-color" )
|
||
|
setForegroundColor( stringToColor( element.text() ) );
|
||
|
else if ( tagName == "background-color" )
|
||
|
setBackgroundColor( stringToColor( element.text() ) );
|
||
|
else if ( tagName == "knotes-richtext" )
|
||
|
mRichText = ( element.text() == "true" );
|
||
|
else
|
||
|
return KolabBase::loadAttribute( element );
|
||
|
|
||
|
// We handled this
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool Note::saveAttributes( TQDomElement& element ) const
|
||
15 years ago
|
{
|
||
|
// Save the base class elements
|
||
|
KolabBase::saveAttributes( element );
|
||
|
|
||
|
// Save the elements
|
||
|
#if 0
|
||
15 years ago
|
TQDomComment c = element.ownerDocument().createComment( "Note specific attributes" );
|
||
15 years ago
|
element.appendChild( c );
|
||
|
#endif
|
||
|
|
||
|
writeString( element, "summary", summary() );
|
||
14 years ago
|
if ( foregroundColor().isValid() )
|
||
|
writeString( element, "foreground-color", colorToString( foregroundColor() ) );
|
||
|
if ( backgroundColor().isValid() )
|
||
|
writeString( element, "background-color", colorToString( backgroundColor() ) );
|
||
15 years ago
|
writeString( element, "knotes-richtext", mRichText ? "true" : "false" );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
bool Note::loadXML( const TQDomDocument& document )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement top = document.documentElement();
|
||
15 years ago
|
|
||
|
if ( top.tagName() != "note" ) {
|
||
13 years ago
|
tqWarning( "XML error: Top tag was %s instead of the expected note",
|
||
15 years ago
|
top.tagName().ascii() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if ( !loadAttribute( e ) )
|
||
|
// TODO: Unhandled tag - save for later storage
|
||
|
kdDebug() << "Warning: Unhandled tag " << e.tagName() << endl;
|
||
|
} else
|
||
|
kdDebug() << "Node is not a comment or an element???" << endl;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Note::saveXML() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomDocument document = domTree();
|
||
|
TQDomElement element = document.createElement( "note" );
|
||
15 years ago
|
element.setAttribute( "version", "1.0" );
|
||
|
saveAttributes( element );
|
||
|
document.appendChild( element );
|
||
|
return document.toString();
|
||
|
}
|
||
|
|
||
|
void Note::setFields( const KCal::Journal* journal )
|
||
|
{
|
||
|
KolabBase::setFields( journal );
|
||
|
|
||
|
setSummary( journal->summary() );
|
||
14 years ago
|
|
||
|
TQString property = journal->customProperty( "KNotes", "BgColor" );
|
||
|
if ( !property.isNull() ) {
|
||
|
setBackgroundColor( property );
|
||
|
} else {
|
||
|
setBackgroundColor( "yellow" );
|
||
|
}
|
||
|
property = journal->customProperty( "KNotes", "FgColor" );
|
||
|
if ( !property.isNull() ) {
|
||
|
setForegroundColor( property );
|
||
|
} else {
|
||
|
setForegroundColor( "black" );
|
||
|
}
|
||
|
|
||
|
property = journal->customProperty( "KNotes", "RichText" );
|
||
|
if ( !property.isNull() ) {
|
||
|
setRichText( property == "true" ? true : false );
|
||
|
} else {
|
||
|
setRichText( "false" );
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
void Note::saveTo( KCal::Journal* journal )
|
||
|
{
|
||
|
KolabBase::saveTo( journal );
|
||
|
|
||
|
// TODO: background and foreground
|
||
|
journal->setSummary( summary() );
|
||
14 years ago
|
if ( foregroundColor().isValid() )
|
||
|
journal->setCustomProperty( "KNotes", "FgColor",
|
||
|
colorToString( foregroundColor() ) );
|
||
|
if ( backgroundColor().isValid() )
|
||
|
journal->setCustomProperty( "KNotes", "BgColor",
|
||
|
colorToString( backgroundColor() ) );
|
||
15 years ago
|
journal->setCustomProperty( "KNotes", "RichText",
|
||
|
richText() ? "true" : "false" );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Note::productID() const
|
||
15 years ago
|
{
|
||
13 years ago
|
return TQString( "KNotes %1, Kolab resource" ).arg( KNOTES_VERSION );
|
||
15 years ago
|
}
|