Logo Search packages:      
Sourcecode: kmess version File versions

emoticonwidget.cpp

/***************************************************************************
                          emoticonwidget.cpp -  description
                             -------------------
    begin                : Sun Dev 11 2005
    copyright            : (C) 2005 by Diederik van der Boor
    email                : "vdboor" --at-- "codingdomain.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 "emoticonwidget.h"

#include <klistbox.h>
#include <kstddirs.h>

#include <qdir.h>


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


// Constructor
EmoticonWidget::EmoticonWidget(QWidget* parent, const char* name)
  : EmoticonWidgetInterface(parent, name)
{
  // the other properties of the widget are initialized
  // in the loadSettings() method
}



// Destructor
EmoticonWidget::~EmoticonWidget()
{
  
}



// Load the settings of the dialog
void EmoticonWidget::loadSettings(Account *account)
{
  // Read the settings
  emoticonStyle_ = account->getEmoticonStyle();

  // Update the widgets
  updateEmoticonList();
}



// Save the settings in the account object.
void EmoticonWidget::saveSettings( Account *account)
{
  account->setEmoticonStyle( emoticonList_->currentText() );
}



// Initialize the widget
void EmoticonWidget::updateEmoticonList()
{
  emoticonList_->clear();

  // Browse all emoticon dirs, to get all emoticons
  QStringList themeDirs = KGlobal::dirs()->findDirs("emoticons", "");

  //kdDebug() << "EmoticonWidget::updateEmoticons: theme dirs=" << themeDirs << endl;

  for(unsigned int x = 0; x < themeDirs.count(); x++)
  {
    // Browse for all themes in the emoticon dir
    QDir themeDir(themeDirs[x]);
    QStringList themeDirs = themeDir.entryList( QDir::Dirs, QDir::Name | QDir::IgnoreCase );
    for( QStringList::Iterator it = themeDirs.begin(); it != themeDirs.end(); ++it )
    {
      QString dirName = *it;

      // Ignore '.' and '..'
      if( dirName == "." || dirName == ".." )
      {
        continue;
      }

      // Add the theme to the list, using the directory name
      // TODO: use the first emoticon of the theme, preferably parse the theme with an EmoticonTheme class.
      //kdDebug() << "EmoticonWidget::updateEmoticons: found " << dirName << endl;
      QPixmap previewPixmap( locate("emoticons", dirName + "/smile.png") );
      emoticonList_->insertItem(previewPixmap, dirName);
    }
  }

  // Highlight the selected emoticon
  QListBoxItem *item = emoticonList_->findItem( emoticonStyle_, Qt::ExactMatch | Qt::CaseSensitive );
  if(item == 0)
  {
    kdWarning() << "Current emoticon style was not found, attempting to revert to the default setting." << endl;
    item = emoticonList_->findItem("KMess", Qt::ExactMatch);
  }

  // If there is an item, select it
  if(item != 0)
  {
    emoticonList_->setCurrentItem( item );
  }
  else
  {
    // select the first item otherwise
    emoticonList_->setCurrentItem( 0 );
  }
}



// The install button was clicked
void EmoticonWidget::slotInstallEmoticons()
{
  
}



#include "emoticonwidget.moc"


Generated by  Doxygen 1.6.0   Back to index