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
#include <klocale.h>
00033
#include <kmessagebox.h>
00034
#include <ksockaddr.h>
00035
00036
#include "knotesnetsend.h"
00037
#include "knotesglobalconfig.h"
00038
00039
00040
#define CONNECT_TIMEOUT 10
00041
00042
00043 KNotesNetworkSender::KNotesNetworkSender(
const QString& hostname,
00044
const QString& title,
const QString& text )
00045 : KExtendedSocket( hostname, KNotesGlobalConfig::port() ),
00046
00047
00048
00049 m_note( text.ascii() ),
00050 m_title( title.ascii() ),
00051 m_index( 0 )
00052 {
00053 enableRead(
false );
00054 enableWrite(
false );
00055 setBlockingMode(
true );
00056 setTimeout( CONNECT_TIMEOUT );
00057
00058 QObject::connect(
this, SIGNAL(connectionSuccess()), SLOT(slotConnected()) );
00059 QObject::connect(
this, SIGNAL(connectionFailed(
int )), SLOT(slotError(
int )) );
00060 QObject::connect(
this, SIGNAL(closed(
int )), SLOT(slotClosed(
int )) );
00061 QObject::connect(
this, SIGNAL(readyWrite()), SLOT(slotReadyWrite()) );
00062
00063
00064 connect();
00065 }
00066
00067
void KNotesNetworkSender::slotConnected()
00068 {
00069
const QString& sender = KNotesGlobalConfig::senderID();
00070
if ( sender.isEmpty() )
00071 m_note.prepend( m_title +
"\n");
00072
else
00073 m_note.prepend( m_title +
" (" + sender.ascii() +
")\n" );
00074
00075 enableWrite(
true );
00076 }
00077
00078
void KNotesNetworkSender::slotReadyWrite()
00079 {
00080 m_index += writeBlock( m_note.data() + m_index, m_note.length() - m_index );
00081
00082
00083
if ( m_index == m_note.length() )
00084 closeNow();
00085 }
00086
00087
void KNotesNetworkSender::slotError(
int errorCode )
00088 {
00089 KMessageBox::sorry( 0, i18n(
"Communication error: %1").arg(
00090 strError( status(), errorCode ) ) );
00091 slotClosed( 0 );
00092 }
00093
00094
void KNotesNetworkSender::slotClosed(
int )
00095 {
00096
delete this;
00097 }
00098
00099
#include "knotesnetsend.moc"