TDE personal information management applications
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.
 
 
 
 
 
 

105 lines
3.7 KiB

  1. /*******************************************************************
  2. KNotes -- Notes for the KDE project
  3. Copyright (c) 2003, Daniel Martin <daniel.martin@pirack.com>
  4. 2004, 2006, Michael Brade <brade@kde.org>
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. In addition, as a special exception, the copyright holders give
  17. permission to link the code of this program with any edition of
  18. the TQt library by Trolltech AS, Norway (or with modified versions
  19. of TQt that use the same license as TQt), and distribute linked
  20. combinations including the two. You must obey the GNU General
  21. Public License in all respects for all of the code used other than
  22. TQt. If you modify this file, you may extend this exception to
  23. your version of the file, but you are not obligated to do so. If
  24. you do not wish to do so, delete this exception statement from
  25. your version.
  26. *******************************************************************/
  27. #include <tdelocale.h>
  28. #include <tdemessagebox.h>
  29. #include "knotesnetsend.h"
  30. #define CONNECT_TIMEOUT 10000
  31. KNotesNetworkSender::KNotesNetworkSender( const TQString& hostname, int port )
  32. : TDEBufferedSocket( hostname, TQString::number( port ) ),
  33. m_note( 0 ), m_title( 0 ), m_sender( 0 ), m_index( 0 )
  34. {
  35. enableRead( false );
  36. enableWrite( false );
  37. setTimeout( CONNECT_TIMEOUT );
  38. // TQObject:: prefix needed, otherwise the KStreamSocket::connect()
  39. // mehtod is called!!!
  40. QObject::connect( TQT_TQOBJECT(this), TQT_SIGNAL(connected( const KResolverEntry& )),
  41. TQT_SLOT(slotConnected( const KResolverEntry& )) );
  42. QObject::connect( TQT_TQOBJECT(this), TQT_SIGNAL(gotError( int )), TQT_SLOT(slotError( int )) );
  43. QObject::connect( TQT_TQOBJECT(this), TQT_SIGNAL(closed()), TQT_SLOT(slotClosed()) );
  44. QObject::connect( TQT_TQOBJECT(this), TQT_SIGNAL(readyWrite()), TQT_SLOT(slotReadyWrite()) );
  45. }
  46. void KNotesNetworkSender::setSenderId( const TQString& sender )
  47. {
  48. m_sender = sender.ascii();
  49. }
  50. void KNotesNetworkSender::setNote( const TQString& title, const TQString& text )
  51. {
  52. // TODO: support for unicode and rich text.
  53. // Mmmmmm... how to behave with such heterogeneous environment?
  54. // AFAIK, ATnotes does not allow UNICODE.
  55. m_title = title.ascii();
  56. m_note = text.ascii();
  57. }
  58. void KNotesNetworkSender::slotConnected( const KResolverEntry& )
  59. {
  60. if ( m_sender.isEmpty() )
  61. m_note.prepend( m_title + "\n");
  62. else
  63. m_note.prepend( m_title + " (" + m_sender + ")\n" );
  64. enableWrite( true );
  65. }
  66. void KNotesNetworkSender::slotReadyWrite()
  67. {
  68. m_index += writeBlock( m_note.data() + m_index, m_note.length() - m_index );
  69. // If end of text reached, close connection
  70. if ( m_index == m_note.length() )
  71. close();
  72. }
  73. void KNotesNetworkSender::slotError( int err )
  74. {
  75. KMessageBox::sorry( 0, i18n("Communication error: %1")
  76. .arg( TQString(KNetwork::TDESocketBase::errorString( static_cast<TDESocketBase::SocketError>(err) )) )
  77. );
  78. slotClosed();
  79. }
  80. void KNotesNetworkSender::slotClosed()
  81. {
  82. deleteLater();
  83. }
  84. #include "knotesnetsend.moc"