knotesnetsend.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <klocale.h>
00034 #include <kmessagebox.h>
00035 #include <ksockaddr.h>
00036
00037 #include "knotesnetsend.h"
00038
00039
00040 #define CONNECT_TIMEOUT 10
00041
00042
00043 KNotesNetworkSender::KNotesNetworkSender( const QString& hostname, int port )
00044 : KExtendedSocket( hostname, port )
00045 {
00046 enableRead( false );
00047 enableWrite( false );
00048 setBlockingMode( true );
00049 setTimeout( CONNECT_TIMEOUT );
00050
00051 QObject::connect( this, SIGNAL(connectionSuccess()), SLOT(slotConnected()) );
00052 QObject::connect( this, SIGNAL(connectionFailed( int )), SLOT(slotError( int )) );
00053 QObject::connect( this, SIGNAL(closed( int )), SLOT(slotClosed( int )) );
00054 QObject::connect( this, SIGNAL(readyWrite()), SLOT(slotReadyWrite()) );
00055 }
00056
00057 void KNotesNetworkSender::setSenderId( const QString& sender )
00058 {
00059 m_sender = sender.ascii();
00060 }
00061
00062 void KNotesNetworkSender::setNote( const QString& title, const QString& text )
00063 {
00064
00065
00066
00067 m_title = title.ascii();
00068 m_note = text.ascii();
00069 }
00070
00071 void KNotesNetworkSender::slotConnected()
00072 {
00073 if ( m_sender.isEmpty() )
00074 m_note.prepend( m_title + "\n");
00075 else
00076 m_note.prepend( m_title + " (" + m_sender + ")\n" );
00077
00078 enableWrite( true );
00079 }
00080
00081 void KNotesNetworkSender::slotReadyWrite()
00082 {
00083 m_index += writeBlock( m_note.data() + m_index, m_note.length() - m_index );
00084
00085
00086 if ( m_index == m_note.length() )
00087 closeNow();
00088 }
00089
00090 void KNotesNetworkSender::slotError( int errorCode )
00091 {
00092 KMessageBox::sorry( 0, i18n("Communication error: %1").arg(
00093 strError( status(), errorCode ) ) );
00094 slotClosed( 0 );
00095 }
00096
00097 void KNotesNetworkSender::slotClosed( int )
00098 {
00099 delete this;
00100 }
00101
00102 #include "knotesnetsend.moc"
This file is part of the documentation for knotes Library Version 3.3.2.