From 46b4e2b360396ec1fd2f597dabf9b8789aa15da2 Mon Sep 17 00:00:00 2001 From: tpearson Date: Sun, 13 Dec 2009 20:19:49 +0000 Subject: Remaining kdenetwork updates: * Kopete emoticons editor dialog and misc. config fixes git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1062109 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../appearance/appearanceconfig_emoticons.ui | 11 + .../config/appearance/emoticonseditdialog.cpp | 256 +++++++++++++++++++++ .../kopete/config/appearance/emoticonseditdialog.h | 55 +++++ .../config/appearance/emoticonseditwidget.ui | 87 +++++++ 4 files changed, 409 insertions(+) create mode 100644 kopete/kopete/config/appearance/emoticonseditdialog.cpp create mode 100644 kopete/kopete/config/appearance/emoticonseditdialog.h create mode 100644 kopete/kopete/config/appearance/emoticonseditwidget.ui diff --git a/kopete/kopete/config/appearance/appearanceconfig_emoticons.ui b/kopete/kopete/config/appearance/appearanceconfig_emoticons.ui index 01652e9f..03020976 100644 --- a/kopete/kopete/config/appearance/appearanceconfig_emoticons.ui +++ b/kopete/kopete/config/appearance/appearanceconfig_emoticons.ui @@ -120,6 +120,17 @@ Edit the selected emoticons theme + + + btnEditThemes + + + &Edit Theme... + + + Edit the selected emoticons theme + + btnInstallTheme diff --git a/kopete/kopete/config/appearance/emoticonseditdialog.cpp b/kopete/kopete/config/appearance/emoticonseditdialog.cpp new file mode 100644 index 00000000..edd5f49b --- /dev/null +++ b/kopete/kopete/config/appearance/emoticonseditdialog.cpp @@ -0,0 +1,256 @@ +#include "emoticonseditdialog.h" +#include "emoticonseditwidget.h" + +#include "kopeteglobal.h" +#include "kopeteprefs.h" +#include "kopeteemoticons.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +EditDialog::EditDialog(QWidget *parent, const char* name) + : KDialogBase(parent, name, true, i18n(name), Ok|Cancel, Ok, true) +{ + setupDlg(); +} + +EditDialog::EditDialog(QWidget *parent, const char* name, QPixmap emot, QString text, QString file) + : KDialogBase(parent, name, true, i18n(name), Ok|Cancel, Ok, true) +{ + setupDlg(); + leText->setText(text); + btnIcon->setPixmap(emot); + emoticon = file; +} + +void EditDialog::setupDlg() +{ + wdg = new QWidget(this); + QVBoxLayout *vl = new QVBoxLayout(wdg, 11, 6); + QHBoxLayout *hb = new QHBoxLayout(wdg, 0, 6); + leText = new KLineEdit(wdg); + btnIcon = new KPushButton(wdg); + btnIcon->setFixedSize(QSize(64, 64)); + + vl->addWidget(new QLabel(i18n("Insert the string for the emoticon\nseparated by space if you want multiple strings"), wdg)); + hb->addWidget(btnIcon); + hb->addWidget(leText); + vl->addLayout(hb); + setMainWidget(wdg); + connect(btnIcon, SIGNAL(clicked()), this, SLOT(btnIconClicked())); +} + +void EditDialog::btnIconClicked() +{ + KURL url = KFileDialog::getImageOpenURL(); + + if(!url.isLocalFile()) + return; + + emoticon = url.path(); + + if(emoticon.isEmpty()) + return; + + btnIcon->setPixmap(QPixmap(emoticon)); +} + +EmoticonsEditDialog::EmoticonsEditDialog(QWidget *parent, QString theme, const char* name) + : KDialogBase(parent, name, true, i18n("Emoticons Editor"), Ok|Cancel, Ok, true) +{ + themeName = theme; + + mMainWidget = new EmoticonsEditWidget(this, "EmoticonsEditDialog::mMainWidget"); + setMainWidget(mMainWidget); + resize(QSize(450, 350)); + mMainWidget->btnAdd->setGuiItem(KStdGuiItem::add()); + mMainWidget->btnEdit->setText(i18n("Edit...")); + mMainWidget->btnRemove->setGuiItem(KStdGuiItem::remove()); + + + mMainWidget->klvEmoticons->addColumn("Emoticon"); + mMainWidget->klvEmoticons->addColumn("Text"); + mMainWidget->klvEmoticons->addColumn("File", 0); + mMainWidget->klvEmoticons->header()->hide(); + Kopete::Emoticons emoticons( theme ); + QMap smileys = emoticons.emoticonAndPicList(); + + + for(QMap::Iterator it = smileys.begin(); it != smileys.end(); ++it ) + { + KListViewItem *itm = new KListViewItem(mMainWidget->klvEmoticons); + itm->setPixmap(0, QPixmap(it.key())); + itm->setText(2, QFileInfo(it.key()).baseName()); + QString text = *it.data().at(0); + for(uint i = 1; i < it.data().size(); i++) { + text += " " + *it.data().at(i); + } + itm->setText(1, text); + } + + QFile *fp = new QFile(KGlobal::dirs()->saveLocation( "emoticons", themeName, false ) + "/emoticons.xml"); + + if( !fp->exists() ) { + kdWarning() << "EmoticonsEditDialog::EmoticonsEditDialog() " << fp->name() << " doesn't exist!" << endl; + return; + } + + if(!fp->open( IO_ReadOnly )) { + kdWarning() << "EmoticonsEditDialog::EmoticonsEditDialog() " << fp->name() << " can't open ReadOnly!" << endl; + return; + } + + if(!themeXml.setContent(fp)) { + kdWarning() << "EmoticonsEditDialog::EmoticonsEditDialog() " << fp->name() << " can't copy to xml!" << endl; + fp->close(); + return; + } + + fp->close(); + + mMainWidget->klvEmoticons->setColumnWidth(0, QListView::Maximum); + mMainWidget->klvEmoticons->setColumnWidth(1, QListView::Maximum); + + connect(this, SIGNAL(okClicked()), this, SLOT(slotOkClicked())); + connect(mMainWidget->btnAdd, SIGNAL(clicked()), this, SLOT(slotAddClicked())); + connect(mMainWidget->btnEdit, SIGNAL(clicked()), this, SLOT(slotEditClicked())); + connect(mMainWidget->btnRemove, SIGNAL(clicked()), this, SLOT(slotRemoveClicked())); +} + +void EmoticonsEditDialog::slotOkClicked() +{ + QFile *fp = new QFile(KGlobal::dirs()->saveLocation( "emoticons", themeName, false ) + "/emoticons.xml"); + + if( !fp->exists() ) { + kdWarning() << "EmoticonsEditDialog::slotOkClicked() " << fp->name() << " doesn't exist!" << endl; + return; + } + + if(!fp->open( IO_WriteOnly )) { + kdWarning() << "EmoticonsEditDialog::slotOkClicked() " << fp->name() << " can't open WriteOnly!" << endl; + return; + } + + QTextStream emoStream(fp); + emoStream << themeXml.toString(4); + fp->close(); +} + +void EmoticonsEditDialog::slotAddClicked() +{ + EditDialog *dlg = new EditDialog(this, "Add emoticon"); + + if(dlg->exec() == QDialog::Rejected) + return; + + if(dlg->getText().isEmpty() || !dlg->getEmoticon()) + return; + + addEmoticon(dlg->getEmoticon(), dlg->getText(), true); + + + delete dlg; +} + +void EmoticonsEditDialog::slotEditClicked() +{ + if(!mMainWidget->klvEmoticons->selectedItem()) + return; + + dlg = new EditDialog(this, "Edit emoticon", *mMainWidget->klvEmoticons->selectedItem()->pixmap(0), mMainWidget->klvEmoticons->selectedItem()->text(1), mMainWidget->klvEmoticons->selectedItem()->text(2)); + + if(dlg->exec() == QDialog::Rejected) + return; + + if(dlg->getText().isEmpty() || !dlg->getEmoticon()) + return; + + bool copy; + QString emo = dlg->getEmoticon(); + if(mMainWidget->klvEmoticons->selectedItem()->text(2) != dlg->getEmoticon()) { + copy = true; + } else { + copy = false; + QString f = mMainWidget->klvEmoticons->selectedItem()->text(2); + + KStandardDirs *dir = KGlobal::dirs(); + emo = dir->findResource( "emoticons", themeName + QString::fromLatin1( "/" ) + f ); + + if( emo.isNull() ) + emo = dir->findResource( "emoticons", themeName + QString::fromLatin1( "/" ) + f + QString::fromLatin1( ".mng" ) ); + if ( emo.isNull() ) + emo = dir->findResource( "emoticons", themeName + QString::fromLatin1( "/" ) + f + QString::fromLatin1( ".png" ) ); + if ( emo.isNull() ) + emo = dir->findResource( "emoticons", themeName + QString::fromLatin1( "/" ) + f + QString::fromLatin1( ".gif" ) ); + if ( emo.isNull() ) + return; + } + + removeEmoticon(mMainWidget->klvEmoticons->selectedItem()->text(2)); + addEmoticon(emo, dlg->getText(), copy); + + delete dlg; +} + +void EmoticonsEditDialog::slotRemoveClicked() +{ + if(!mMainWidget->klvEmoticons->selectedItem()) + return; + + removeEmoticon(mMainWidget->klvEmoticons->selectedItem()->text(2)); +} + +void EmoticonsEditDialog::addEmoticon(QString emo, QString text, bool copy) +{ + if(copy) + KIO::copy(emo, KGlobal::dirs()->saveLocation( "emoticons", themeName, false )); + + KListViewItem *itm = new KListViewItem(mMainWidget->klvEmoticons); + itm->setPixmap(0, QPixmap(emo)); + itm->setText(1, text); + itm->setText(2, QFileInfo(emo).baseName()); + + QDomNode lc = themeXml.lastChild(); + if(lc.isNull()) + return; + + QDomElement emoticon = themeXml.createElement("emoticon"); + emoticon.setAttribute("file", QFileInfo(emo).baseName()); + lc.appendChild(emoticon); + QStringList splitted = QStringList::split(" ", text); + QStringList::const_iterator constIterator; + for(constIterator = splitted.begin(); constIterator != splitted.end(); constIterator++) + { + QDomElement emotext = themeXml.createElement("string"); + QDomText txt = themeXml.createTextNode((*constIterator).stripWhiteSpace()); + emotext.appendChild(txt); + emoticon.appendChild(emotext); + } +} + +void EmoticonsEditDialog::removeEmoticon(QString emo) +{ + QDomNode lc = themeXml.lastChild(); + if(lc.isNull()) + return; + + QDomNodeList nl = lc.childNodes(); + + for(uint i = 0; i < nl.length(); i++) { + QDomElement de = nl.item(i).toElement(); + if(!de.isNull() && de.tagName() == "emoticon" && de.attribute("file") == emo) { + lc.removeChild(de); + delete mMainWidget->klvEmoticons->selectedItem(); + return; + } + } +} + diff --git a/kopete/kopete/config/appearance/emoticonseditdialog.h b/kopete/kopete/config/appearance/emoticonseditdialog.h new file mode 100644 index 00000000..1dab47e1 --- /dev/null +++ b/kopete/kopete/config/appearance/emoticonseditdialog.h @@ -0,0 +1,55 @@ +#ifndef EMOTICONSEDITDIALOG_H +#define EMOTICONSEDITDIALOG_H + +#include +#include +#include +#include +#include +#include +#include + +class EmoticonsEditWidget; + +class EditDialog : public KDialogBase +{ + Q_OBJECT + + public: + EditDialog(QWidget *parent, const char* name); + EditDialog(QWidget *parent, const char* name, QPixmap emot, QString text, QString file); + const QString getText() { return leText->text(); }; + const QString getEmoticon() { return emoticon; }; + private slots: + void btnIconClicked(); + private: + void setupDlg(); + QWidget *wdg; + KLineEdit *leText; + KPushButton *btnIcon; + QString emoticon; +}; + +class EmoticonsEditDialog : public KDialogBase +{ + Q_OBJECT + + public: + EmoticonsEditDialog(QWidget *parent=0, QString theme = QString::null, const char* name="EmoticonsEditDialog"); + void addEmoticon(QString emo, QString text, bool copy); + + private slots: + void slotOkClicked(); + void slotAddClicked(); + void slotEditClicked(); + void slotRemoveClicked(); + + private: + void removeEmoticon(QString emo); + EmoticonsEditWidget *mMainWidget; + QString themeName; + EditDialog *dlg; + QDomDocument themeXml; +}; + +#endif diff --git a/kopete/kopete/config/appearance/emoticonseditwidget.ui b/kopete/kopete/config/appearance/emoticonseditwidget.ui new file mode 100644 index 00000000..10f0b6ca --- /dev/null +++ b/kopete/kopete/config/appearance/emoticonseditwidget.ui @@ -0,0 +1,87 @@ + +EmoticonsEditWidget + + + EmoticonsEditWidget + + + + 0 + 0 + 535 + 378 + + + + EmoticonsEditWidget + + + + unnamed + + + + layout5 + + + + unnamed + + + + btnAdd + + + Add... + + + + + btnEdit + + + Edit... + + + + + btnRemove + + + Remove + + + + + spacer4 + + + Vertical + + + Expanding + + + + 20 + 40 + + + + + + + + klvEmoticons + + + + + + + kpushbutton.h + kpushbutton.h + kpushbutton.h + klistview.h + + -- cgit v1.2.3