• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.12
  • kdepim
  • knotes
  • network
knotesnetsend.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 2003, Daniel Martin <daniel.martin@pirack.com>
5  2004, 2006, Michael Brade <brade@kde.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  as published by the Free Software Foundation; either version 2
10  of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 *******************************************************************/
32 
33 #include "knotesnetsend.h"
34 
35 #include <klocale.h>
36 #include <kmessagebox.h>
37 
38 #include <QTextCodec>
39 
40 KNotesNetworkSender::KNotesNetworkSender( QTcpSocket *socket )
41  : QObject(), m_socket( socket ), m_note(), m_title(), m_sender()
42 {
43  // QObject:: prefix needed, otherwise the KStreamSocket::connect()
44  // method is called!!!
45  QObject::connect( m_socket, SIGNAL(connected()), SLOT(slotConnected()) );
46  QObject::connect( m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
47  SLOT(slotError()) );
48  QObject::connect( m_socket, SIGNAL(disconnected()), SLOT(slotClosed()) );
49  QObject::connect( m_socket, SIGNAL(bytesWritten(qint64)),
50  SLOT(slotWritten(qint64)) );
51 }
52 
53 KNotesNetworkSender::~KNotesNetworkSender()
54 {
55  delete m_socket;
56 }
57 
58 void KNotesNetworkSender::setSenderId( const QString &sender )
59 {
60  QTextCodec *codec = QTextCodec::codecForLocale();
61  m_sender = codec->fromUnicode( sender );
62 }
63 
64 void KNotesNetworkSender::setNote( const QString &title, const QString &text )
65 {
66  QTextCodec *codec = QTextCodec::codecForLocale();
67  m_title = codec->fromUnicode( title );
68  m_note = codec->fromUnicode( text );
69 }
70 
71 void KNotesNetworkSender::slotConnected()
72 {
73  if ( m_sender.isEmpty() ) {
74  m_note.prepend( m_title + "\n" );
75  } else {
76  m_note.prepend( m_title + " (" + m_sender + ")\n" );
77  }
78 
79  m_socket->write( m_note );
80 }
81 
82 void KNotesNetworkSender::slotWritten( qint64 )
83 {
84  // If end of text reached, close connection
85  if ( m_socket->bytesToWrite() == 0 ) {
86  m_socket->close();
87  }
88 }
89 
90 void KNotesNetworkSender::slotError()
91 {
92  KMessageBox::sorry( 0, i18n( "Communication error: %1",
93  m_socket->errorString() ) );
94  slotClosed();
95 }
96 
97 void KNotesNetworkSender::slotClosed()
98 {
99  deleteLater();
100 }
101 
102 #include "knotesnetsend.moc"
knotesnetsend.h
KNotesNetworkSender::KNotesNetworkSender
KNotesNetworkSender(QTcpSocket *socket)
Definition: knotesnetsend.cpp:40
QObject
KNotesNetworkSender::slotConnected
void slotConnected()
Definition: knotesnetsend.cpp:71
KNotesNetworkSender::slotWritten
void slotWritten(qint64)
Definition: knotesnetsend.cpp:82
KNotesNetworkSender::slotError
void slotError()
Definition: knotesnetsend.cpp:90
KNotesNetworkSender::slotClosed
void slotClosed()
Definition: knotesnetsend.cpp:97
KNotesNetworkSender::~KNotesNetworkSender
~KNotesNetworkSender()
Definition: knotesnetsend.cpp:53
KNotesNetworkSender::setNote
void setNote(const QString &title, const QString &text)
Definition: knotesnetsend.cpp:64
KNotesNetworkSender::setSenderId
void setSenderId(const QString &sender)
Definition: knotesnetsend.cpp:58
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal