Logo Search packages:      
Sourcecode: kmess version File versions

account.cpp

/***************************************************************************
                          account.cpp  -  description
                             -------------------
    begin                : Sun Jan 5 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 "account.h"

#include "msnobject.h"

#include <qdir.h>
#include <qregexp.h>

#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmdcodec.h>
#include <kstandarddirs.h>
#include <kapplication.h>

#include "kmessdebug.h"

#ifdef KMESSDEBUG_ACCOUNT
  #define KMESSDEBUG_ACCOUNT_GENERAL
  #define KMESSDEBUG_ACCOUNT_DIRTY
#endif

// The constructor
Account::Account()
 : autoreplyMessage_( i18n("I'm away from my computer") ),
   chatStyle_( "Default" ),
   contactFontColor_("#000000"),
   customImageIndex_(0),
   deleted_(false),
   dirty_(false),
   emailCommand_("kmail"),
   emailSupported_(true),  // Assume true (for new accounts), until the msn server proves the opposite
   emoticonStyle_("KMess-new"),
   fontColor_("#000000"),
   friendlyName_( i18n("Your name") ),
   guestAccount_(true),
   groupFollowupMessages_(false),
   handle_( i18n("you@hotmail.com") ),
   idleTime_(5),
   notificationDuration_(10),
   saveChats_(false),
   savedChatDirectoryStructure_( 0 ),
   shakeNudge_(true),
   showAllowedContacts_(false),
   showContactsByGroup_(true),
   showEmail_(true),
   showMessageTime_(true),
   showNowListening_(false),
   showOfflineContacts_(true),
   showOfflineNotification_(true),
   showOtherFolders_(true),
   showRemovedContacts_(false),
   showSidebar_(true),
   startInvisible_(false),
   useAutologin_(false),
   useContactFont_(false),
   useEmoticons_(true),
   useFontEffects_(true),
   useHotmail_(true),
   useIdleTimer_(true),
   useNotifier_(true),

   useProxy_(false),
   verified_(true),
   proxyType_(TYPE_HTTP),
   proxyPort_(80),

   showImage_(true),
   msnObject_(0)
{
  QDir homeDir;

  font_.setFamily("Arial");
  font_.setBold(false);
  font_.setItalic(false);
  font_.setUnderline(false);
  font_.setPointSize(12);

  contactFont_.setFamily("Arial");
  contactFont_.setBold(false);
  contactFont_.setItalic(false);
  contactFont_.setUnderline(false);

  homeDir = QDir::home();
  saveChatPath_ = homeDir.absPath();
}



// The destructor
Account::~Account()
{
  if ( msnObject_ )
    delete msnObject_;

#ifdef KMESSDEBUG_ACCOUNT_GENERAL
  kdDebug() << "DESTROYED Account " << handle_ << endl;
#endif
}



// Copy an account
void Account::copyAccount( const Account *account )
{
  // This method is called to write information from a global Account
  // object to the CurrentAccount and visa-versa.
  // See also: copyAccountUISettings() for properties only changed by the GUI.

  setLoginInformation( account->getHandle(), account->getFriendlyName(), account->getPassword() );
  setShowAllowedContacts( account->getShowAllowedContacts() );
  setShowContactsByGroup( account->getShowContactsByGroup() );
  setShowOfflineContacts( account->getShowOfflineContacts() );
  setShowRemovedContacts( account->getShowRemovedContacts() );
  setEmoticonStyle      ( account->getEmoticonStyle()       );

  setAlertsInformation      ( account->getUseIdleTimer(),
                              account->getIdleTime(),
                              account->getUseNotifier(),
                              account->getNotificationDuration(),
                              account->getShowOfflineNotification(),
                              account->getShakeNudge(),
                              account->getShowNowListening() );
  setChatInformation        ( account->getUseContactFont(),
                              account->getUseEmoticons(),
                              account->getUseFontEffects(),
                              account->getShowMessageTime(),
                              account->getGroupFollowupMessages(),
                              account->getChatStyle()                     );
  setChatLoggingInformation ( account->getSaveChats(),
                              account->getSaveChatPath(),
                              account->getSavedChatDirectoryStructure()   );
  setEmailInformation       ( account->getUseHotmail(),
                              account->getEmailCommand(),
                              account->getShowEmail(),
                              account->getShowOtherFolders()              );
  setEmailSupported         ( account->getEmailSupported()                );
  setFontInformation        ( account->getFont(),
                              account->getFontColor(),
                              account->getContactFont(),
                              account->getContactFontColor()              );
  setPersonalMessage        ( account->getPersonalMessage()               );
  setProxyInformation       ( account->getUseProxy(),
                              (int)account->getProxyType(),
                              account->getProxyServer(),
                              account->getProxyPort(),
                              account->getProxyUID(),
                              account->getProxyPassword()                 );

  setUseAutologin           ( account->getUseAutologin()                  );
  setAutoreplyMessage       ( account->getAutoreplyMessage()              );
  setShowSidebar            ( account->getShowSidebar()                   );
  setStartInvisible         ( account->getStartInvisible()                );
  setGuestAccount           ( account->isGuestAccount()                   );

  setShowImage              ( account->getShowImage()                     );
  setTemporaryPassword      ( account->getTemporaryPassword()             );
  setVerified               ( account->isVerified()                       );

  customImageIndex_ = account->customImageIndex_;
  updateMsnObject();
}



// Copy an account's user-interface, not settings, changable properties
void Account::copyAccountUISettings( const Account *account )
{
  // All properties that are modified through the main gui are listed here.
  setPersonalMessage    ( account->getPersonalMessage()     );
  setShowAllowedContacts( account->getShowAllowedContacts() );
  setShowOfflineContacts( account->getShowOfflineContacts() );
  setShowRemovedContacts( account->getShowRemovedContacts() );
  setShowContactsByGroup( account->getShowContactsByGroup() );
  setAutoreplyMessage   ( account->getAutoreplyMessage()    );
  setEmailSupported     ( account->getEmailSupported()      );
  setGuestAccount       ( account->isGuestAccount()         );
  setShowSidebar        ( account->getShowSidebar()         );
  setVerified           ( account->isVerified()             );
  customImageIndex_ = account->customImageIndex_;
}



// Delete the account data
void Account::deleteAccountData()
{
  // Can be called twice, avoid warnings.
  if( deleted_ )
  {
    return;
  }

#ifdef KMESSDEBUG_KMESS
  kdDebug() << "Account::deleteAccountData: deleting configuration fields" << endl;
#endif

  KConfig     *config = kapp->config();
  QString      groupName;
  QStringList  groups = config->groupList();

  // Delete Profile_<handle>
  if( ! config->deleteGroup("Profile_" + handle_) )
  {
    kdWarning() << "Account::deleteAccountData: Could not remove 'Profile_" << handle_ << "' from the config file!" << endl;
  }

  // Delete Contact_<handle>/<contacthandle>
  QString contactPrefix = "Contact_" + handle_ + "/";
  for( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it )
  {
    groupName = *it;
    if( groupName.startsWith(contactPrefix) )
    {
      if( ! config->deleteGroup(groupName) )
      {
        kdWarning() << "Account::deleteAccountData: Could not remove '" << groupName << "' from the config file!" << endl;
      } 
    }
  }

  // Mark as deleted, so other classes avoid saving the settings again.
  deleted_      = true;
  guestAccount_ = true;
}



// Read the auto-reply message.
const QString& Account::getAutoreplyMessage() const
{
  return autoreplyMessage_;
}



// Return the chat style name.
const QString& Account::getChatStyle() const
{
  return chatStyle_;
}



// Return the font used for contact messages, if forced to.
const QFont& Account::getContactFont() const
{
  return contactFont_;
}



// Return the color of the forced contact font.
const QString& Account::getContactFontColor() const
{
  return contactFontColor_;
}



// Read the email command used when not using hotmail
const QString& Account::getEmailCommand() const
{
  return emailCommand_;
}


// Return whether email notifications are supported
bool Account::getEmailSupported() const
{
  return emailSupported_;
}


// Return the user message font.
const QFont& Account::getFont() const
{
  return font_;
}



// Return the color of the user message font.
const QString& Account::getFontColor() const
{
  return fontColor_;
}



// Return the user's friendlyName
QString Account::getFriendlyName() const
{
  return friendlyName_;
}



// Whether follow-up messages from the contact should be grouped.
bool Account::getGroupFollowupMessages() const
{
  return groupFollowupMessages_;
}



// Return the user's handle
QString Account::getHandle() const
{
  return handle_;
}



// Return the length of time waited before the user goes idle.
const int& Account::getIdleTime() const
{
  return idleTime_;
}



// Return the path for a new the custom display image.
QString Account::getNewCustomImagePath()
{
  customImageIndex_++;  // Ensures the image name is always unique, so the ChatWindow's KHTMLPart doesn't cache the image.
  QString imageRoot  = ::locateLocal("data", "kmess");
  QString safeHandle = getHandle().lower().replace( QRegExp( "[^a-z0-9_.@]" ), "-" );
  return imageRoot + "/msnpicture-" + safeHandle + "-" + QString::number(customImageIndex_)  + ".png";
}



// Return the time popup windows are shown.
const int& Account::getNotificationDuration() const
{
  return notificationDuration_;
}



// Return whether now listening information should be displayed.
bool Account::getShowNowListening() const
{
  return showNowListening_;
}



// Return the user's password
QString Account::getPassword() const
{
  return password_;
}



// Return the personal message
QString Account::getPersonalMessage() const
{
  return personalMessage_;
}



// Return the proxy password
const QString& Account::getProxyPassword() const
{
  return proxyPassword_;
}



// Return the proxy port
const int& Account::getProxyPort()  const
{
  return proxyPort_;
}



// Return the proxy server IP
const QString& Account::getProxyServer() const
{
  return proxyServer_;
}



// Return the proxy server type
const int& Account::getProxyType() const
{
  return (int)proxyType_;
}



// Return the user's proxy user ID
const QString& Account::getProxyUID() const
{
  return proxyUID_;
}



// Return the selected emoticon's style
const QString& Account::getEmoticonStyle() const
{
  return emoticonStyle_;
}



// Return whether or not to save chats.
bool Account::getSaveChats() const
{
  return saveChats_;
}



// Return the base directory to which chats are saved.
const QString& Account::getSaveChatPath() const
{
  return saveChatPath_;
}



// Return the code of the structure used to save chats.
const int& Account::getSavedChatDirectoryStructure() const
{
  return savedChatDirectoryStructure_;
}



// Read whether the chat window should shake when a nudge is received or sent.
bool Account::getShakeNudge() const
{
  return shakeNudge_;
}



// Read whether or not allowed contacts are shown.
bool Account::getShowAllowedContacts() const
{
  return showAllowedContacts_;
}



// Read whether contacts are shown by group or by online/offline.
bool Account::getShowContactsByGroup() const
{
  return showContactsByGroup_;
}



// Read whether the email information should be shown in the main view.
bool Account::getShowEmail() const
{
  return showEmail_;
}



// Read whether message times should be shown.
bool Account::getShowMessageTime() const
{
  return showMessageTime_;
}



// Read whether offline contacts should be shown.
bool Account::getShowOfflineContacts() const
{
  return showOfflineContacts_;
}



// Read property of bool showOfflineNotification_.
bool Account::getShowOfflineNotification() const
{
  return showOfflineNotification_;
}



// Read property of bool showOtherFolders.
bool Account::getShowOtherFolders() const
{
  return showOtherFolders_;
}



// Read whether or not removed (reverse) contacts are shown.
bool Account::getShowRemovedContacts() const
{
  return showRemovedContacts_;
}



// Read whether or not the sidebar should be shown in chats
bool Account::getShowSidebar() const
{
  return showSidebar_;
}



// Return whether or not to start in "hidden" mode
bool Account::getStartInvisible() const
{
  return startInvisible_;
}



// Return the a temporary password for the account for login attempts from the initialview dialog
const QString & Account::getTemporaryPassword() const
{
  return temporaryPassword_;
}



// Return whether or not to autologin with this profile.
bool Account::getUseAutologin() const
{
  return useAutologin_;
}



// Return whether or not to show contact messages in the stored font.
bool Account::getUseContactFont() const
{
  return useContactFont_;
}



// Return whether or not to show emoticons in chats.
bool Account::getUseEmoticons() const
{
  return useEmoticons_;
}



// Return whether or not to use the bold/italic/underline effects.
bool Account::getUseFontEffects() const
{
  return useFontEffects_;
}



// Read whether the user uses hotmail to read email or a set command
bool Account::getUseHotmail() const
{
  return useHotmail_;
}



// Return whether the idle timer should be used.
bool Account::getUseIdleTimer() const
{
  return useIdleTimer_;
}



// Return whether or not to show popup notifications.
bool Account::getUseNotifier() const
{
  return useNotifier_;
}



// Return whether or not to use a proxy.
bool Account::getUseProxy() const
{
  return useProxy_;
}



// Returns whether or not to send our display image
bool Account::getShowImage() const
{
  return showImage_;
}



// Return the path of the custom display image.
const QString Account::getCustomImagePath() const
{
  QString safeHandle = getHandle().lower().replace( QRegExp( "[^a-z0-9_.@]" ), "-" );
  QString suffix     = ( customImageIndex_ > 0 ? "-" + QString::number(customImageIndex_) : QString::null );
  return ::locateLocal("data", "kmess/msnpicture-" + safeHandle + suffix + ".png");
}



// Return the path to the *current* display image
const QString Account::getImagePath() const
{
  KStandardDirs *dirs = KGlobal::dirs();
  QString imagePath;

  // return image path if user has selected to show it else return QString::null
  if( showImage_ )
  {
    // if the user has selected a custom image it will be located (usually) in
    // ~/.kde/share/apps/kmess/msnpicture-handle.png
    imagePath = getCustomImagePath();

    // If the file can't be found, fallback to the default image.
    if(! QFile::exists(imagePath))
    {
      imagePath = dirs->findResource( "data", "kmess/pics/kmesspic.png"  );
    }

    return imagePath;
  }
  else
  {
    return QString::null;
  }
}


// Returns the string representation of the MsnObject
const QString Account::getMsnObjectString() const
{
  if ( msnObject_ )
    return msnObject_->objectString();
  else
    return "";
}



// Whether the account is marked to be deleted
bool Account::isDeleted() const
{
  return deleted_;
}


// Whether the account is a guest account, not permanently saved on the computer
bool Account::isGuestAccount() const
{
  return guestAccount_;
}



// Return whether the account's passport is verified
bool Account::isVerified() const
{
  return verified_;
}



// Read in account properties
void Account::readProperties(KConfig *config, QString handle)
{
  handle_ = handle;
  QDir    homeDir;
  QString defaultPath;

  homeDir = QDir::home();
  defaultPath = homeDir.absPath();

  // Go the the profile's group
  config->setGroup( "Profile_" + handle_ );

  autoreplyMessage_            = config->readEntry    ( "autoreplymessage",            i18n("I'm away from my computer") );
  chatStyle_                   = config->readEntry    ( "chatStyle",                   "Default"                         );
// contactFont_.setFamily done below
  contactFont_.setBold         ( config->readBoolEntry( "contactfontbold",             false                           ) );
  contactFont_.setItalic       ( config->readBoolEntry( "contactfontitalic",           false                           ) );
  contactFont_.setUnderline    ( config->readBoolEntry( "contactfontunderline",        false                           ) );
  contactFont_.setPointSize    ( config->readNumEntry ( "contactfontpointsize",        10                              ) );
  contactFontColor_            = config->readEntry    ( "contactfontcolor" ,           "#000000"                         );
  customImageIndex_            = config->readNumEntry ( "customimageindex",            0                                 ); 
  emailCommand_                = config->readEntry    ( "emailCommand",                "kmail"                           );
  emoticonStyle_               = config->readEntry    ( "emoticonStyle",               "KMess-new"                       );
//font_.setFamily done below
  font_.setBold                ( config->readBoolEntry( "fontbold",                    false                           ) );
  font_.setItalic              ( config->readBoolEntry( "fontitalic",                  false                           ) );
  font_.setUnderline           ( config->readBoolEntry( "fontunderline",               false                           ) );
  font_.setPointSize           ( config->readNumEntry ( "fontpointsize",               12                              ) );
  fontColor_                   = config->readEntry    ( "fontColor" ,                  "#000000"                         );
  friendlyName_                = config->readEntry    ( "friendlyName" ,               QString::null                     );
  groupFollowupMessages_       = config->readBoolEntry( "groupfollowupmessages",       false                             );
  idleTime_                    = config->readNumEntry ( "idleTime",                    5                                 );
  notificationDuration_        = config->readNumEntry ( "notification",                5                                 );
  password_                    = config->readEntry    ( "password" ,                   QString::null                     );
  personalMessage_             = config->readEntry    ( "personalMessage",             QString::null                     );
  saveChatPath_                = config->readEntry    ( "saveChatPath",                defaultPath                       );
  saveChats_                   = config->readBoolEntry( "saveChats",                   false                             );
  savedChatDirectoryStructure_ = config->readNumEntry ( "savedChatDirectoryStructure", 0                                 );
  shakeNudge_                  = config->readBoolEntry( "shakeNudge",                  true                              );
  showAllowedContacts_         = config->readBoolEntry( "showAllowed",                 false                             );
  showContactsByGroup_         = config->readBoolEntry( "showByGroup",                 true                              );
  showEmail_                   = config->readBoolEntry( "showEmail",                   true                              );
  showMessageTime_             = config->readBoolEntry( "showMessageTime",             true                              );
  showNowListening_            = config->readBoolEntry( "showNowListening",            false                             );
  showOfflineContacts_         = config->readBoolEntry( "showOfflineContacts",         true                              );
  showOfflineNotification_     = config->readBoolEntry( "showOfflineNotification",     true                              );
  showOtherFolders_            = config->readBoolEntry( "showOtherFolders",            true                              );
  showRemovedContacts_         = config->readBoolEntry( "showRemoved",                 false                             );
  showSidebar_                 = config->readBoolEntry( "showSidebar",                 true                              );
  startInvisible_              = config->readBoolEntry( "startInvisible",              false                             );
  useAutologin_                = config->readBoolEntry( "useAutologin",                false                             );
  useContactFont_              = config->readBoolEntry( "useContactFont",              false                             );
  useEmoticons_                = config->readBoolEntry( "useEmoticons",                true                              );
  useFontEffects_              = config->readBoolEntry( "useFontEffects",              true                              );
  useHotmail_                  = config->readBoolEntry( "useHotmail",                  true                              );
  useIdleTimer_                = config->readBoolEntry( "useIdleTimer",                true                              );
  useNotifier_                 = config->readBoolEntry( "useNotifier",                 true                              );

  proxyPassword_               = config->readEntry    ( "proxyPassword",               ""                                );
  proxyPort_                   = config->readNumEntry ( "proxyPort",                   1080                              );
  proxyServer_                 = config->readEntry    ( "proxyServer",                 ""                                );
  proxyType_                   = (PROXYTYPE)config->readNumEntry ( "proxyType",        2                                 );//TYPE_SOCKS5
  proxyUID_                    = config->readEntry    ( "proxyUID",                    ""                                );
  useProxy_                    = config->readBoolEntry( "useProxy",                    false                             );

  showImage_                   = config->readBoolEntry( "showImage",                   true                              );

  updateMsnObject();


  // Read font setting, remove accel character if it's still there.
  // That's a KMess 1.3 issue, but still visible in 1.4 if you never changed font settings.
  QString normalFont  = config->readEntry("fontfamily", "Arial");
  QString contactFont = config->readEntry( "contactfontfamily", "Arial");
  font_.setFamily( normalFont.replace("&", QString::null) );
  contactFont_.setFamily( contactFont.replace("&", QString::null) );

  // After reading options from file, consider "dirty" to still be false
  guestAccount_ = false;
  dirty_ = false;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  kdDebug() << "Account:readProperties: Resetting 'dirty' to false." << endl;
#endif

  // If the fonts were auto-corrected, make sure the modified setting is saved in the kmessrc.
  // Avoids questions and discussions like "yes, it's there but that's not a problem". Better just fix it.
  if( normalFont.contains("&") || contactFont.contains("&") )
  {
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account:readProperties: Auto-corrected font & setting, setting 'dirty' to true." << endl;
#endif
    dirty_ = true;
  }
}



// Save account properties
void Account::saveProperties(KConfig *config)
{
  // Protect against unwanted usage
  if( guestAccount_ )
  {
    kdWarning() << "Account::saveProperties: Application attempted to save a guest account!" << endl;
  }
  if( deleted_ )
  {
    kdWarning() << "Account::saveProperties: Application attempted to save the deleted account again!" << endl;
  }

  if ( dirty_ )
  {
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account " << handle_ << " is 'dirty' so save properties." << endl;
#endif
    // Go the the profile's group
    config->setGroup( "Profile_" + handle_ );

    // Remove old chatFormat, replaced by chatStyle
    config->deleteEntry( "chatFormat" );

    config->writeEntry( "autoreplymessage",            autoreplyMessage_            );
    config->writeEntry( "chatStyle",                   chatStyle_                   );
    config->writeEntry( "contactfontfamily",           contactFont_.family()        );
    config->writeEntry( "contactfontbold",             contactFont_.bold()          );
    config->writeEntry( "contactfontitalic",           contactFont_.italic()        );
    config->writeEntry( "contactfontunderline",        contactFont_.underline()     );
    config->writeEntry( "contactfontpointsize",        contactFont_.pointSize()     );
    config->writeEntry( "contactfontcolor",            contactFontColor_            );
    config->writeEntry( "customimageindex",            customImageIndex_            );
    config->writeEntry( "emailCommand",                emailCommand_                );
    config->writeEntry( "emoticonStyle",               emoticonStyle_               );
    config->writeEntry( "fontfamily",                  font_.family()               );
    config->writeEntry( "fontbold",                    font_.bold()                 );
    config->writeEntry( "fontitalic",                  font_.italic()               );
    config->writeEntry( "fontunderline",               font_.underline()            );
    config->writeEntry( "fontpointsize",               font_.pointSize()            );
    config->writeEntry( "fontColor",                   fontColor_                   );
    config->writeEntry( "friendlyName",                friendlyName_                );
    config->writeEntry( "groupfollowupmessages",       groupFollowupMessages_       );
    config->writeEntry( "idleTime",                    idleTime_                    );
    config->writeEntry( "notification",                notificationDuration_        );
    config->writeEntry( "password",                    password_                    );
    config->writeEntry( "personalMessage",             personalMessage_             );
    config->writeEntry( "saveChatPath",                saveChatPath_                );
    config->writeEntry( "saveChats",                   saveChats_                   );
    config->writeEntry( "savedChatDirectoryStructure", savedChatDirectoryStructure_ );
    config->writeEntry( "shakeNudge",                  shakeNudge_                  );
    config->writeEntry( "showAllowed",                 showAllowedContacts_         );
    config->writeEntry( "showByGroup",                 showContactsByGroup_         );
    config->writeEntry( "showEmail",                   showEmail_                   );
    config->writeEntry( "showMessageTime",             showMessageTime_             );
    config->writeEntry( "showNowListening",            showNowListening_            );
    config->writeEntry( "showOfflineContacts",         showOfflineContacts_         );
    config->writeEntry( "showOfflineNotification",     showOfflineNotification_     );
    config->writeEntry( "showOtherFolders",            showOtherFolders_            );
    config->writeEntry( "showRemoved",                 showRemovedContacts_         );
    config->writeEntry( "showSidebar",                 showSidebar_                 );
    config->writeEntry( "startInvisible",              startInvisible_              );
    config->writeEntry( "useAutologin",                useAutologin_                );
    config->writeEntry( "useContactFont",              useContactFont_              );
    config->writeEntry( "useEmoticons",                useEmoticons_                );
    config->writeEntry( "useFontEffects",              useFontEffects_              );
    config->writeEntry( "useHotmail",                  useHotmail_                  );
    config->writeEntry( "useIdleTimer",                useIdleTimer_                );
    config->writeEntry( "useNotifier",                 useNotifier_                 );

    config->writeEntry( "proxyPassword",               proxyPassword_               );
    config->writeEntry( "proxyPort",                   proxyPort_                   );
    config->writeEntry( "proxyServer",                 proxyServer_                 );
    config->writeEntry( "proxyType",              (int)proxyType_                   );
    config->writeEntry( "proxyUID",                    proxyUID_                    );
    config->writeEntry( "useProxy",                    useProxy_                    );

    config->writeEntry( "showImage",                   showImage_                   );
  }
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  else
  {
    kdDebug() << "Account " << handle_ << " is clean so DO NOT save properties." << endl;
  }
#endif
}



// The login succeeded with the new password. Save the temporary password as new account password.
void Account::saveTemporaryPassword()
{
  if( ! temporaryPassword_.isEmpty() )
  {
    password_ = temporaryPassword_;
  }
}



// Set alert information
void Account::setAlertsInformation( bool useIdleTimer, int idleTime, bool useNotifier, int notificationDuration, bool showOfflineNotification, bool shakeNudge, bool showNowListening )
{
  useIdleTimer_ = useIdleTimer;
  idleTime_ = idleTime;
  useNotifier_ = useNotifier;
  notificationDuration_ = notificationDuration;
  showOfflineNotification_ = showOfflineNotification;
  shakeNudge_ = shakeNudge;

  emit changedTimerSettings();

  if( showNowListening_ != showNowListening )
  {
#ifdef KMESSDEBUG_ACCOUNT_GENERAL
    kdDebug() << "Now listening settings changed, notifying listeners." << endl;
#endif

    showNowListening_ = showNowListening;
    emit changedNowListeningSettings();
  }

  dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  kdDebug() << "Account Setting 'dirty' to true - setAlertsInformation." << endl;
#endif
}



// Set the auto-reply message.
void Account::setAutoreplyMessage( const QString& autoreplyMessage)
{
  if ( autoreplyMessage_ != autoreplyMessage )
  {
    autoreplyMessage_ = autoreplyMessage;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setAutoreplyMessage." << endl;
#endif
  }
}



// Set chat information
void Account::setChatInformation( bool useContactFont, bool useEmoticons, bool useFontEffects,
                                  bool showMessageTime, bool groupFollowupMessages, const QString& chatStyle )
{
  bool changedSettings = (useContactFont_        != useContactFont)
                      || (useEmoticons_          != useEmoticons)
                      || (useFontEffects_        != useFontEffects)
                      || (showMessageTime_       != showMessageTime)
                      || (groupFollowupMessages_ != groupFollowupMessages)
                      || (chatStyle_             != chatStyle);

  // Avoid signals because the chat windows will regenerate all messages.
  if( ! changedSettings )
  {
    return;
  }

  useContactFont_        = useContactFont;
  useEmoticons_          = useEmoticons;
  useFontEffects_        = useFontEffects;
  showMessageTime_       = showMessageTime;
  groupFollowupMessages_ = groupFollowupMessages;
  chatStyle_             = chatStyle;
  emit changedChatStyleSettings();
  dirty_ = true;

#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  kdDebug() << "Account Setting 'dirty' to true - setChatInformation." << endl;
#endif
}



// Set chat logging information
void Account::setChatLoggingInformation( bool saveChats, const QString& saveChatPath, const int& directoryStructure )
{
  if( saveChats_                   != saveChats
  ||  saveChatPath_                != saveChatPath
  ||  savedChatDirectoryStructure_ != directoryStructure )
  {
    saveChats_                   = saveChats;
    saveChatPath_                = saveChatPath;
    savedChatDirectoryStructure_ = directoryStructure;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setChatLoggingInformation." << endl;
#endif
  }
}



// Set email information
void Account::setEmailInformation( bool useHotmail, const QString& emailCommand, bool showEmail, bool showOtherFolders )
{
  if( useHotmail_       != useHotmail
  ||  emailCommand_     != emailCommand
  ||  showEmail_        != showEmail
  ||  showOtherFolders_ != showOtherFolders )
  {
    useHotmail_       = useHotmail;
    emailCommand_     = emailCommand;
    showEmail_        = showEmail;
    showOtherFolders_ = showOtherFolders;

    emit changedEmailDisplaySettings();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setEmailInformation." << endl;
#endif
  }
}



// Update the email-supported state (protected method)
void Account::setEmailSupported(bool emailSupported)
{
  emailSupported_ = emailSupported; 
}



// Set the font
void Account::setFont( const QFont& font )
{
  if( font != font_ )
  {
    font_ = font;
    emit changedFontSettings();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setFont." << endl;
#endif
  }
}



// Set the font color
void Account::setFontColor( const QString& fontColor )
{
  if( fontColor != fontColor_ )
  {
    fontColor_ = fontColor;
    emit changedFontSettings();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setFontColor." << endl;
#endif
  }
}




// Set the fonts and font colors
void Account::setFontInformation( const QFont& font, const QString &fontColor, const QFont& contactFont, const QString &contactFontColor)
{
  bool changedSettings = (font_ != font)
                      || (fontColor_ != fontColor)
                      || (contactFont_ != contactFont)
                      || (contactFontColor_ != contactFontColor);

  // Avoid signals because the chat windows will regenerate all messages.
  if( ! changedSettings )
  {
    return;
  }

  font_             = font;
  fontColor_        = fontColor;
  contactFont_      = contactFont;
  contactFontColor_ = contactFontColor;
  emit changedFontSettings();
  dirty_ = true;

#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  kdDebug() << "Account Setting 'dirty' to true - setFontInformation." << endl;
#endif
}



// Set the emoticon path
void Account::setEmoticonStyle( const QString& emoticonStyle )
{
  if( emoticonStyle != emoticonStyle_ )
  {
    // Set the new style, and signal EmoticonCollection about it.
    emoticonStyle_ = emoticonStyle;
    emit changedEmoticonSettings();

    // Tell the account settings changed and need to be saved
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setEmoticonStyle." << endl;
#endif
  }
}



// Change the friendly name
void Account::setFriendlyName(const QString& newName)
{
  if ( ( newName != "" ) && ( newName != friendlyName_ ) )
  {
    friendlyName_ = newName;
    emit changedFriendlyName();
    dirty_ = true;
  }
}



// Whether the account is a guest account, not permanently saved on the computer
void Account::setGuestAccount( bool guestAccount )
{
  guestAccount_ = guestAccount;

  // Undelete when user did restore the account.
  if( ! guestAccount_ )
  {
    deleted_ = false;
  }
}



// Set basic account data
void Account::setLoginInformation( QString handle, QString friendlyName, QString password )
{
#ifdef KMESSTEST
  ASSERT( handle.contains("@") );
  ASSERT( handle != "" );
#endif

  if( handle_       != handle
  ||  friendlyName_ != friendlyName
  ||  ( ! password.isEmpty() && password != password_ ) )
  {
    handle_       = handle;
    friendlyName_ = friendlyName;
    emit changedFriendlyName();

    if( ! password.isEmpty() )
    {
      password_ = password;
    }

    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setLoginInformation." << endl;
#endif
  }
}



// Set the personal message
void Account::setPersonalMessage(const QString& newMessage)
{
  if( newMessage != personalMessage_ )
  {
    personalMessage_ = newMessage;
    emit changedPersonalMessage();

    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setPersonalMessage." << endl;
#endif
  }
}



// Set proxy information
void Account::setProxyInformation( bool useproxy, const int& proxytype,const QString& proxyserver, const int& proxyport,const QString& proxyuid, const QString& password )
{
  if( useProxy_      != useproxy
  ||  proxyServer_   != proxyserver
  ||  proxyPort_     != proxyport
  ||  proxyUID_      != proxyuid
  ||  proxyPassword_ != password
  ||  proxyType_     != (PROXYTYPE) proxytype )
  {
    useProxy_      = useproxy;
    proxyServer_   = proxyserver;
    proxyPort_     = proxyport;
    proxyUID_      = proxyuid;
    proxyPassword_ = password;
    proxyType_     = (PROXYTYPE)proxytype;
    dirty_         = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setProxyInformation." << endl;
#endif
  }
}



// Set whether or not allowed contacts are shown.
void Account::setShowAllowedContacts( bool showAllowedContacts )
{
  if( showAllowedContacts != showAllowedContacts_ )
  {
    showAllowedContacts_ = showAllowedContacts;
    emit changedDisplaySettings();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setShowAllowedContacts." << endl;
#endif
  }
}




// Set whether contacts are shown by group or by online/offline.
void Account::setShowContactsByGroup( bool showContactsByGroup )
{
  if ( showContactsByGroup != showContactsByGroup_ )
  {
    showContactsByGroup_ = showContactsByGroup;
    emit changedViewMode();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setShowContactsByGroup." << endl;
#endif
  }
}



// Set whether offline contacts should be shown.
void Account::setShowOfflineContacts( bool showOfflineContacts )
{
  if( showOfflineContacts != showOfflineContacts_ )
  {
    showOfflineContacts_ = showOfflineContacts;
    emit changedDisplaySettings();
    dirty_ = true;
  }
}



// Set whether or not removed (reverse) contacts are shown.
void Account::setShowRemovedContacts( bool showRemovedContacts )
{
  if( showRemovedContacts != showRemovedContacts_ )
  {
    showRemovedContacts_ = showRemovedContacts;
    emit changedDisplaySettings();
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setShowRemovedContacts." << endl;
#endif
  }
}



// Set whether or not the sidebar should be shown in chats
void Account::setShowSidebar( bool showSidebar )
{
  if ( showSidebar_ != showSidebar )
  {
    showSidebar_ = showSidebar;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setShowSidebar." << endl;
#endif
  }
}



// Set whether or not to start in "hidden" mode
void Account::setStartInvisible( bool startInvisible )
{
  if( startInvisible != startInvisible_ )
  {
    startInvisible_ = startInvisible;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setStartInvisible." << endl;
#endif
  }
}



// Set a temporary password for the account for login attempts from the initialview dialog
void Account::setTemporaryPassword( const QString &temporaryPassword )
{
  temporaryPassword_ = temporaryPassword;
}



// Set whether or not to login with this account.
void Account::setUseAutologin( bool useAutologin)
{
  if( useAutologin != useAutologin_ )
  {
    useAutologin_ = useAutologin;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account Setting 'dirty' to true - setUseAutologin." << endl;
#endif
  }
}



// Set whether or not to show emoticons in chats.
void Account::setUseEmoticons( bool useEmoticons)
{
  useEmoticons_ = useEmoticons;
  dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
  kdDebug() << "Account Setting 'dirty' to true - setUseEmoticons." << endl;
#endif
}



// Set whether the account's passport is verified
void Account::setVerified( bool verified )
{
  verified_ = verified;
}



// Set whether or not to send our display image
void Account::setShowImage( bool showImage )
{
  if( showImage != showImage_ )
  {
    showImage_ = showImage;
    dirty_ = true;
#ifdef KMESSDEBUG_ACCOUNT_DIRTY
    kdDebug() << "Account: Setting 'dirty' to true - setShowImage." << endl;
#endif
  }
}



// Creates the MsnObject only if the user wants to show a display picture
void Account::updateMsnObject()
{
  QString oldMsnString;
  QString newMsnString;

  if( msnObject_ )
  {
    oldMsnString = msnObject_->objectString();
    delete msnObject_;
    msnObject_ = 0;
  }

#ifdef KMESSDEBUG_ACCOUNT_GENERAL
  kdDebug() << "Account::updateMsnObject: Show Image: " << showImage_ << endl;
#endif

  if ( showImage_ )
  {
#ifdef KMESSDEBUG_ACCOUNT_GENERAL
    kdDebug() << "Account::updateMsnObject: Image source: " << getImagePath() << endl;
#endif

    QFile iFile( getImagePath() );
    if ( iFile.open( IO_ReadOnly ) )
    {
      QByteArray data = iFile.readAll();
      iFile.close();

      msnObject_   = new MsnObject( handle_, "KMess.tmp", "", MsnObject::DISPLAYPIC, data );
      newMsnString = msnObject_->objectString();
    }
    else
    {
#ifdef KMESSDEBUG_ACCOUNT_GENERAL
      kdDebug() << "Account::updateMsnObject: Image could not be loaded: " << getImagePath() << endl;
#endif
    }
  }

  // Detect if there was a change.
  if(oldMsnString != newMsnString)
  {
#ifdef KMESSDEBUG_ACCOUNT_GENERAL
    kdDebug() << "Account::updateMsnObject: result is: '" << newMsnString << "'" << endl;
#endif
    emit changedMsnObject();
  }
}


#include "account.moc"

Generated by  Doxygen 1.6.0   Back to index