knotes Library API Documentation

knotesnetsend.cpp

00001 /******************************************************************* 00002 KNotes -- Notes for the KDE project 00003 00004 Copyright (c) 2003, Daniel Martin <daniel.martin@pirack.com> 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the Qt library by Trolltech AS, Norway (or with modified versions 00023 of Qt that use the same license as Qt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 Qt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 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 // This comes in seconds! 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 // TODO: support for unicode and richtext. 00047 // Mmmmmm... how to behave with such heterogeneous environment? 00048 // AFAIK, ATnotes does not allow UNICODE. 00049 m_note( text.ascii() ), 00050 m_title( title.ascii() ), 00051 m_index( 0 ) 00052 { 00053 enableRead( false ); 00054 enableWrite( false ); 00055 setBlockingMode( true ); // Recommended by documentation. 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 // The error signal will take care of errors 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 // If end of text reached, close connection 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 /*state*/ ) 00095 { 00096 delete this; 00097 } 00098 00099 #include "knotesnetsend.moc"
KDE Logo
This file is part of the documentation for knotes Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:15 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003