Logo Search packages:      
Sourcecode: kmess version File versions

initialview.cpp

/***************************************************************************
                          initialview.cpp  -  description
                             -------------------
    begin                : Sun Jan 12 2003
    copyright            : (C) 2003 by Mike K. Bennett
    email                : mkb137b@hotmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "initialview.h"

#include <qcheckbox.h>
#include <qlabel.h>
#include <qlineedit.h>

#include <kapp.h>
#include <kcombobox.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <kglobalsettings.h>

#include "account.h"
#include "kmessdebug.h"


// The constructor
InitialView::InitialView(QWidget *parent, const char *name )
 : InitialViewInterface(parent, name)
{
  // Set the username box with the last used email address
  config_ = kapp->config();
  config_->setGroup( "InitialView" );
  defaultHandle_ = config_->readEntry( "defaultHandle", "me@hotmail.com" );

  // Enable auto completion
  handleCombobox_->setCompletionMode( KGlobalSettings::CompletionPopup );

  // Load the KMess icon
  KIconLoader *loader = KGlobal::iconLoader();
  QPixmap icon = loader->loadIcon( "kmesslogo", KIcon::User );
  kmessLogo_->setPixmap( icon );
  kmessLogo_->setMinimumSize( icon.width(), icon.height() );
}



// The destructor
InitialView::~InitialView()
{
#ifdef KMESSDEBUG_INITIALVIEW
  kdDebug() << "DESTROYED InitialView" << endl;
#endif
}



// Add an account to the list of displayed accounts from which the user can choose
void InitialView::addAccount(Account *account)
{
  const QString &handle = account->getHandle();

  // Add account to internal list
  accounts_.insert( handle, account );

  // Add an entry for the account to the dropdown list
  handleCombobox_->insertItem( handle ); // + " (" + account->getFriendlyName() + ")" );
  handleCombobox_->completionObject()->addItem( handle );

  // Select the account in the combobox if it's the default account.
  if( handle == defaultHandle_ )
  {
    handleCombobox_->setCurrentItem( defaultHandle_ );
    profileSelected( handleCombobox_->currentItem() ); 
  }
}



// The "connect" button was pressed.
void InitialView::connectToMsn()
{
  // Save the entered text
  QString handle = getSelectedHandle();
  config_->setGroup( "InitialView" );
  config_->writeEntry( "defaultHandle", handle );

  // Inform parent with the account information
  emit connectWithAccount( handle, passwordEdit_->text(), rememberCheckBox_->isChecked() );
}



// The account was deleted
void InitialView::deleteAccount(Account *account)
{
  // Remove account from hashmap.
  QString handle = account->getHandle();
  accounts_.remove(handle);

  // Remove account from completionbox (extended qlistbox)
  handleCombobox_->completionObject()->removeItem( handle );

  // Remove account from qcombobox
  bool foundItem = false;
  for( int i = 0; i < handleCombobox_->count(); i++ )
  {
    if( handleCombobox_->text(i) == handle )
    {
      handleCombobox_->removeItem(i);
      foundItem = true;
      break;
    }
  }

  if( ! foundItem )
  {
    kdWarning() << "InitialView::deleteAccount: Account not found in pulldown list!" << endl;
  }
}



// The text in the handle box has changed
void InitialView::handleTextChanged(const QString &/*text*/)
{
  Account *account = accounts_[getSelectedHandle()];
  if( account != 0 )
  {
    // User typed the full account name without using autocompletion.
    passwordEdit_->setText( account->getPassword() );
  }
  else
  {
    // User typed a new account name
    // Clear password again
    passwordEdit_->setText( QString::null );
  }
}



// Get the currently selected handle
QString InitialView::getSelectedHandle() const
{
  // Get handle, remove appended friendlyname if present
  QString handle = handleCombobox_->currentText();
  if( handle.contains(' ') )
  {
    handle = handle.section(' ', 0, 0);
  }
  return handle;
}



// The profile with the given index was selected from the drop-down list.
void InitialView::profileSelected(int /*index*/)
{
  // Set the password of account it it exists
  Account *account = accounts_[ getSelectedHandle() ];
  if( account == 0 )
  {
    kdWarning() << "InitialView::profileSelected: no account found for handle '" << getSelectedHandle() << "'" << endl;
    return;
  }

  passwordEdit_->setText( account->getPassword() );
}


#include "initialview.moc"

Generated by  Doxygen 1.6.0   Back to index