Logo Search packages:      
Sourcecode: kmess version File versions  Download package

msnsocketbase.cpp

/***************************************************************************
                          msnsocketbase.cpp  -  description
                             -------------------
    begin                : Thu Apr 1 2008
    copyright            : (C) 2008 by Valerio Pilo
    email                : valerio@kmess.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "msnsocketbase.h"

#include <QAuthenticator>
#include <QNetworkProxy>

#include <KLocale>
#include <KPasswordDialog>
#include <kdeversion.h>


/**
 * @brief The constructor
 */
00031 MsnSocketBase::MsnSocketBase( ServerType serverType )
: connected_( false )
{
  // Set the type of server the derived socket will connect to
  serverType_ = serverType;
}



/**
 * @brief The destructor
 *
 * Does nothing.
 */
00045 MsnSocketBase::~MsnSocketBase()
{
}



/**
 * @brief Return which payload commands are accepted by this connection
 *
 * Returns the list of payload messages which this connection needs to accept.
 *
 * @return List of 3-letter commands which are recognized as carrying payload.
 */
00058 QStringList MsnSocketBase::getAcceptedPayloadCommands()
{
  return acceptedPayloadCommands_;
}



/**
 * @brief Return the type of server connection managed by the socket
 */
00068 MsnSocketBase::ServerType MsnSocketBase::getServerType() const
{
  return serverType_;
}



/**
 * @brief Whether or not the connection is active
 *
 * @returns True when connected, false otherwise.
 */
00080 bool MsnSocketBase::isConnected() const
{
  return ( connected_ );
}



/**
 * @brief Test whether the given command is an error.
 *
 * @param command Command to verify
 * @returns True when it's an error command, false otherwise.
 */
00093 bool MsnSocketBase::isErrorCommand( const QString &command ) const
{
  bool isNumeric = false;
  return ( command.toInt( &isNumeric ) != 0 ) && ( isNumeric == true );
}



/**
 * @brief Test whether the given command is a payload command.
 *
 * @param command Command to verify
 * @returns True when it's a payload command, false otherwise.
 */
00107 bool MsnSocketBase::isPayloadCommand( const QString &command ) const
{
  return acceptedPayloadCommands_.contains( command );
}



// Ask the user to authenticate on a proxy
void MsnSocketBase::proxyAuthenticate( const QNetworkProxy &proxy, QAuthenticator *authenticator )
{
#ifdef KMESSDEBUG_SHARED_PROXY_AUTH
  kDebug() << "Authentication to proxy" << proxy.hostName() << "required.";
  kDebug() << "Realm:" << authenticator->realm() << "Username:" << authenticator->user();
#else
  Q_UNUSED( proxy );
#endif

  KPasswordDialog::KPasswordDialogFlags flags =
                                                KPasswordDialog::ShowUsernameLine
#if KDE_IS_VERSION( 4, 1, 0 )
                                              | KPasswordDialog::ShowDomainLine
                                              | KPasswordDialog::DomainReadOnly
                                              | KPasswordDialog::ShowAnonymousLoginCheckBox
#endif
                                              | KPasswordDialog::ShowKeepPassword;

  KPasswordDialog loginDialog( 0, flags );
  loginDialog.setPrompt( i18nc( "Dialog box message",
                                "Enter your username and password to access the network proxy." ) );

  // The user canceled
  if( ! loginDialog.exec() )
  {
      return;
  }

  authenticator->setUser( loginDialog.username() );
  authenticator->setPassword( loginDialog.password() );
}



/**
 * @brief Specify which accepted commands carry payload data for this connection.
 *
 * Within different kinds of connection, server messages can be different or
 * have different meanings; this method ensures that every kind of connection
 * is able to recognize its own payload commands only.
 *
 * @param commandList List of 3-letter commands which will be recognized as carrying payload.
 */
00158 void MsnSocketBase::setAcceptedPayloadCommands( QStringList commandList )
{
  acceptedPayloadCommands_ = commandList;
}



#include "msnsocketbase.moc"

Generated by  Doxygen 1.6.0   Back to index