diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-12-13 20:19:49 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-12-13 20:19:49 +0000 |
commit | 46b4e2b360396ec1fd2f597dabf9b8789aa15da2 (patch) | |
tree | fa5e7cc0ff1e3ffe1b4239e268fff9bf761c371e | |
parent | 9fab5b8a216e283e563f3457315715672bc8b55a (diff) | |
download | tdenetwork-46b4e2b360396ec1fd2f597dabf9b8789aa15da2.tar.gz tdenetwork-46b4e2b360396ec1fd2f597dabf9b8789aa15da2.zip |
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
4 files changed, 409 insertions, 0 deletions
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 @@ -122,6 +122,17 @@ </widget> <widget class="QPushButton"> <property name="name"> + <cstring>btnEditThemes</cstring> + </property> + <property name="text"> + <string>&Edit Theme...</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Edit the selected emoticons theme</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> <cstring>btnInstallTheme</cstring> </property> <property name="text"> 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 <klocale.h> +#include <klistview.h> +#include <kstandarddirs.h> +#include <kfiledialog.h> +#include <kio/job.h> +#include <qpixmap.h> +#include <qheader.h> +#include <qlayout.h> +#include <qlabel.h> + + +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<QString, QStringList> smileys = emoticons.emoticonAndPicList(); + + + for(QMap<QString, QStringList>::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 <kdebug.h> +#include <qhbox.h> +#include <kdialogbase.h> +#include <klineedit.h> +#include <kpushbutton.h> +#include <qfile.h> +#include <qdom.h> + +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 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>EmoticonsEditWidget</class> +<widget class="QWidget"> + <property name="name"> + <cstring>EmoticonsEditWidget</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>535</width> + <height>378</height> + </rect> + </property> + <property name="caption"> + <string>EmoticonsEditWidget</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KPushButton"> + <property name="name"> + <cstring>btnAdd</cstring> + </property> + <property name="text"> + <string>Add...</string> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>btnEdit</cstring> + </property> + <property name="text"> + <string>Edit...</string> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>btnRemove</cstring> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </vbox> + </widget> + <widget class="KListView" row="0" column="0"> + <property name="name"> + <cstring>klvEmoticons</cstring> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> +</includehints> +</UI> |