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.
127 lines
3.0 KiB
127 lines
3.0 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
|
||
|
|
||
|
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.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqfiledialog.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
|
||
|
#include <ktextbrowser.h>
|
||
|
#include <kstaticdeleter.h>
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <klocale.h>
|
||
|
#include "debugdialog.h"
|
||
|
|
||
|
DebugDialog* DebugDialog::mSelf = 0;
|
||
|
static KStaticDeleter<DebugDialog> debugDialogDeleter;
|
||
|
|
||
|
DebugDialog::DebugDialog()
|
||
|
: KDialogBase( Plain, WStyle_DialogBorder | WStyle_StaysOnTop, 0,
|
||
|
"Debug Dialog", false, i18n("Debug Dialog"),
|
||
|
User1 | User2 | Ok, Ok, true )
|
||
|
{
|
||
15 years ago
|
TQWidget *page = plainPage();
|
||
13 years ago
|
TQVBoxLayout *layout = new TQVBoxLayout( page, marginHint(), spacingHint() );
|
||
15 years ago
|
|
||
|
mView = new KTextBrowser( page );
|
||
13 years ago
|
layout->addWidget( mView );
|
||
15 years ago
|
|
||
|
setButtonText( User1, "Save As..." );
|
||
|
setButtonText( User2, "Clear" );
|
||
|
|
||
|
clear();
|
||
|
}
|
||
|
|
||
|
void DebugDialog::init()
|
||
|
{
|
||
|
if ( !mSelf ) {
|
||
|
if ( getenv( "EGROUPWARE_DEBUG" ) != 0 ) {
|
||
|
debugDialogDeleter.setObject( mSelf, new DebugDialog );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( mSelf ) {
|
||
|
mSelf->show();
|
||
|
mSelf->raise();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DebugDialog::~DebugDialog()
|
||
|
{
|
||
|
mSelf = 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
void DebugDialog::addMessage( const TQString &msg, Type type )
|
||
15 years ago
|
{
|
||
|
if ( mSelf )
|
||
|
mSelf->addText( msg, type );
|
||
|
}
|
||
|
|
||
|
void DebugDialog::clear()
|
||
|
{
|
||
|
mView->clear();
|
||
|
mMessages.clear();
|
||
|
}
|
||
|
|
||
|
void DebugDialog::save()
|
||
|
{
|
||
15 years ago
|
TQString fileName = TQFileDialog::getSaveFileName();
|
||
15 years ago
|
if ( fileName.isEmpty() )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQFile file( fileName );
|
||
15 years ago
|
if ( !file.open( IO_WriteOnly ) ) {
|
||
13 years ago
|
tqWarning( "Couldn't open file %s", file.name().latin1() );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
file.writeBlock( mMessages.join( "\n\n" ).utf8() );
|
||
|
file.close();
|
||
|
}
|
||
|
|
||
|
void DebugDialog::slotUser1()
|
||
|
{
|
||
|
save();
|
||
|
}
|
||
|
|
||
|
void DebugDialog::slotUser2()
|
||
|
{
|
||
|
clear();
|
||
|
}
|
||
|
|
||
15 years ago
|
void DebugDialog::addText( const TQString &text, Type type )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString htmlCode( text );
|
||
14 years ago
|
htmlCode.replace( "<", "<" );
|
||
|
htmlCode.replace( ">", ">" );
|
||
|
htmlCode.replace( "\n", "<br>" );
|
||
15 years ago
|
|
||
|
mMessages.append( text );
|
||
|
if ( type == Input )
|
||
|
mHTMLMessages.append( "<font color=\"green\">" + htmlCode + "</font>" );
|
||
|
else
|
||
|
mHTMLMessages.append( "<font color=\"blue\">" + htmlCode + "</font>" );
|
||
|
|
||
|
mView->clear();
|
||
|
mView->setText( mHTMLMessages.join( "<br>" ) );
|
||
|
}
|
||
|
|
||
|
#include "debugdialog.moc"
|