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

void ChatView::slotAddNewEmoticon (  )  [private, slot]

Open a dialog to add a new custom emoticon seen in the chat

Definition at line 709 of file chatview.cpp.

References CurrentAccount::getContactByHandle(), EmoticonManager::instance(), and AddEmoticonDialog::preSelect().

{
  if( ! chatViewClickedUrl_.isValid() || chatViewClickedUrl_.protocol() != "kmess" || chatViewClickedUrl_.host() != "emoticon" )
  {
#ifdef KMESSDEBUG_CHATVIEW
    kdDebug() << "ChatView::slotAddNewEmoticon() - Ignoring request for invalid URL: " << chatViewClickedUrl_.url() << endl;
#endif

    return;
  }

/*
 * Everytime we generate a link to add an emoticon, we have only access to HTML representations of the image, that means tags like:
 * <img src='filename.png&apos; ... />
 * So the least resource-intensive and easy - read: fast - way of passing the image name of the new emoticon to this method is
 * a raw url-encoding of the entire tag, which we decode and split up to extract the filename from the 'src' tag attribute.
 * Hacky, but hopefully with Qt4 we'll find another way.
 *
 * KMess' internal emoticon addition URLs are in the form
 * <code>kmess://emoticon/contactHandle/urlEncodedShortcut/urlEncodedPictureTag</code>
 */

  QString path  = chatViewClickedUrl_.path().mid( 1 );  // remove first /

#ifdef KMESSTEST
  ASSERT( ! path.isEmpty() );
#endif

  // Reset the url
  chatViewClickedUrl_ = KURL();

  QString handle   = path.section( "/", 0, 0 );   // First parameter: contact handle
  QString shortcut = path.section( "/", 1, 1 );   // Second parameter: emoticon shortcut
  QString picture  = path.section( "/", 2    );   // Third parameter: emoticon picture (as an HTML <IMG> tag)

  const ContactBase *contact = CurrentAccount::instance()->getContactByHandle( handle );
  if( contact == 0 )
  {
#ifdef KMESSDEBUG_CHATVIEW
    kdDebug() << "ChatView::slotAddNewEmoticon() - Contact handle not found: " << handle << endl;
#endif

    return;
  }


  // URL-Decode the encoded strings
  picture  = KURL::decode_string( picture  );
  shortcut = KURL::decode_string( shortcut );

  // Strip the emoticon picture name from the tag
  picture = picture.replace( "\"", "'" );
  picture = picture.mid( picture.find( "src='" ) + 5 );
  picture = picture.mid( 0, picture.find( "'" ) );

#ifdef KMESSDEBUG_CHATVIEW
  kdDebug() << "ChatView::slotAddNewEmoticon() - Showing Add Emoticon dialog - shortcut=" << shortcut << " picture=" << picture << endl;
#endif

  // Finally, show the dialog, preselecting the picture file and shortcut
  AddEmoticonDialog *addDialog = new AddEmoticonDialog( EmoticonManager::instance()->getTheme( true ), this, "AddEmoticonDialogChat" );

  connect( addDialog,        SIGNAL( addedEmoticon(QString) ),
           chatMessageView_,   SLOT( addedEmoticon(QString) ) );

  addDialog->preSelect( picture, shortcut );

}


Generated by  Doxygen 1.6.0   Back to index