diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/plugins/alias | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/plugins/alias')
-rw-r--r-- | kopete/plugins/alias/Makefile.am | 19 | ||||
-rw-r--r-- | kopete/plugins/alias/aliasdialog.ui | 193 | ||||
-rw-r--r-- | kopete/plugins/alias/aliasdialogbase.ui | 107 | ||||
-rw-r--r-- | kopete/plugins/alias/aliasplugin.cpp | 38 | ||||
-rw-r--r-- | kopete/plugins/alias/aliasplugin.h | 31 | ||||
-rw-r--r-- | kopete/plugins/alias/aliaspreferences.cpp | 502 | ||||
-rw-r--r-- | kopete/plugins/alias/aliaspreferences.h | 56 | ||||
-rw-r--r-- | kopete/plugins/alias/editaliasdialog.cpp | 51 | ||||
-rw-r--r-- | kopete/plugins/alias/editaliasdialog.h | 38 | ||||
-rw-r--r-- | kopete/plugins/alias/kopete_alias.desktop | 108 | ||||
-rw-r--r-- | kopete/plugins/alias/kopete_alias_config.desktop | 104 |
11 files changed, 1247 insertions, 0 deletions
diff --git a/kopete/plugins/alias/Makefile.am b/kopete/plugins/alias/Makefile.am new file mode 100644 index 00000000..d295e0cc --- /dev/null +++ b/kopete/plugins/alias/Makefile.am @@ -0,0 +1,19 @@ +METASOURCES = AUTO +AM_CPPFLAGS = $(KOPETE_INCLUDES) $(all_includes) + +kde_module_LTLIBRARIES = kopete_alias.la kcm_kopete_alias.la + +kopete_alias_la_SOURCES = aliasplugin.cpp +kopete_alias_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries) +kopete_alias_la_LIBADD = ../../libkopete/libkopete.la + +kcm_kopete_alias_la_SOURCES = aliaspreferences.cpp aliasdialogbase.ui aliasdialog.ui editaliasdialog.cpp +kcm_kopete_alias_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries) +kcm_kopete_alias_la_LIBADD = $(LIB_KOPETECOMPAT) $(LIB_KUTILS) ../../libkopete/libkopete.la + +service_DATA = kopete_alias.desktop +servicedir = $(kde_servicesdir) + +kcm_DATA = kopete_alias_config.desktop +kcmdir = $(kde_servicesdir)/kconfiguredialog + diff --git a/kopete/plugins/alias/aliasdialog.ui b/kopete/plugins/alias/aliasdialog.ui new file mode 100644 index 00000000..1d980d52 --- /dev/null +++ b/kopete/plugins/alias/aliasdialog.ui @@ -0,0 +1,193 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AliasDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>AliasDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>361</width> + <height>268</height> + </rect> + </property> + <property name="caption"> + <string>Add New Alias</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Command:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>command</cstring> + </property> + </widget> + <widget class="KLineEdit" row="1" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>command</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>This is the command that you want to run when you execute this alias. </string> + </property> + <property name="whatsThis" stdset="0"> + <string><qt>This is the command that you want to run when you execute this alias. + +You can use the variables <b>%1, %2 ... %9</b> in your command, and they will be replaced with the arguments of the alias. The variable <b>%s</b> will be replaced with all arguments. <b>%n</b> expands to your nickname. + +Do not include the '/' in the command (if you do it will be stripped off anyway).</qt></string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Alias:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>alias</cstring> + </property> + </widget> + <widget class="KLineEdit" row="0" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>alias</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>This is the alias you are adding (what you will type after the command identifier, '/').</string> + </property> + <property name="whatsThis" stdset="0"> + <string>This is the alias you are adding (what you will type after the command identifier, '/'). Do not include the '/' (it will be stripped off if you do anyway).</string> + </property> + </widget> + <widget class="KPushButton" row="4" column="1"> + <property name="name"> + <cstring>addButton</cstring> + </property> + <property name="text"> + <string>&Save</string> + </property> + <property name="default"> + <bool>false</bool> + </property> + </widget> + <widget class="KPushButton" row="4" column="2"> + <property name="name"> + <cstring>kPushButton3</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + <widget class="KListView" row="2" column="1" rowspan="1" colspan="2"> + <column> + <property name="text"> + <string>Protocols</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>protocolList</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="selectionMode" stdset="0"> + <enum>Multi</enum> + </property> + <property name="itemMargin"> + <number>0</number> + </property> + <property name="resizeMode"> + <enum>AllColumns</enum> + </property> + <property name="fullWidth"> + <bool>true</bool> + </property> + <property name="itemsMovable"> + <bool>false</bool> + </property> + <property name="toolTip" stdset="0"> + <string>If you want this alias to only be active for certain protocols, select those protocols here.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If you want this alias to only be active for certain protocols, select those protocols here.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>For protocols:</string> + </property> + <property name="alignment"> + <set>AlignTop</set> + </property> + <property name="buddy" stdset="0"> + <cstring>kListView2</cstring> + </property> + </widget> + <widget class="Line" row="3" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<connections> + <connection> + <sender>kPushButton3</sender> + <signal>clicked()</signal> + <receiver>AliasDialog</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>addButton</sender> + <signal>clicked()</signal> + <receiver>AliasDialog</receiver> + <slot>accept()</slot> + </connection> +</connections> +<tabstops> + <tabstop>alias</tabstop> + <tabstop>command</tabstop> + <tabstop>protocolList</tabstop> + <tabstop>addButton</tabstop> + <tabstop>kPushButton3</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> +</includehints> +</UI> diff --git a/kopete/plugins/alias/aliasdialogbase.ui b/kopete/plugins/alias/aliasdialogbase.ui new file mode 100644 index 00000000..f70cc5bf --- /dev/null +++ b/kopete/plugins/alias/aliasdialogbase.ui @@ -0,0 +1,107 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>AliasDialogBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AliasDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>602</width> + <height>424</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KListView" row="0" column="0" rowspan="1" colspan="3"> + <column> + <property name="text"> + <string>Alias</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Command</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Protocols</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>aliasList</cstring> + </property> + <property name="selectionMode" stdset="0"> + <enum>Extended</enum> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + <property name="fullWidth"> + <bool>false</bool> + </property> + <property name="itemsMovable"> + <bool>false</bool> + </property> + <property name="whatsThis" stdset="0"> + <string>This is the list of custom aliases and the commands that you have already added</string> + </property> + </widget> + <widget class="KPushButton" row="1" column="0"> + <property name="name"> + <cstring>addButton</cstring> + </property> + <property name="text"> + <string>&Add New Alias...</string> + </property> + </widget> + <widget class="KPushButton" row="1" column="2"> + <property name="name"> + <cstring>deleteButton</cstring> + </property> + <property name="text"> + <string>&Delete Selected</string> + </property> + </widget> + <widget class="KPushButton" row="1" column="1"> + <property name="name"> + <cstring>editButton</cstring> + </property> + <property name="text"> + <string>Edit Alias...</string> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klistview.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/kopete/plugins/alias/aliasplugin.cpp b/kopete/plugins/alias/aliasplugin.cpp new file mode 100644 index 00000000..1594a836 --- /dev/null +++ b/kopete/plugins/alias/aliasplugin.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * * + * 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 <kgenericfactory.h> + +#include "kopetemessagemanagerfactory.h" + +#include "aliasplugin.h" + +typedef KGenericFactory<AliasPlugin> AliasPluginFactory; +K_EXPORT_COMPONENT_FACTORY( kopete_alias, AliasPluginFactory( "kopete_alias" ) ) +AliasPlugin * AliasPlugin::pluginStatic_ = 0L; + +AliasPlugin::AliasPlugin( QObject *parent, const char * name, const QStringList & ) + : Kopete::Plugin( AliasPluginFactory::instance(), parent, name ) +{ + if( !pluginStatic_ ) + pluginStatic_ = this; + +} + +AliasPlugin::~AliasPlugin() +{ + pluginStatic_ = 0L; +} + +AliasPlugin * AliasPlugin::plugin() +{ + return pluginStatic_ ; +} + +#include "aliasplugin.moc" diff --git a/kopete/plugins/alias/aliasplugin.h b/kopete/plugins/alias/aliasplugin.h new file mode 100644 index 00000000..8e55dc20 --- /dev/null +++ b/kopete/plugins/alias/aliasplugin.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef AliasPLUGIN_H +#define AliasPLUGIN_H + +#include "kopeteplugin.h" + +class AliasPlugin : public Kopete::Plugin +{ + Q_OBJECT + + public: + static AliasPlugin *plugin(); + + AliasPlugin( QObject *parent, const char *name, const QStringList &args ); + ~AliasPlugin(); + + private: + static AliasPlugin * pluginStatic_; +}; + +#endif + + diff --git a/kopete/plugins/alias/aliaspreferences.cpp b/kopete/plugins/alias/aliaspreferences.cpp new file mode 100644 index 00000000..65342ddf --- /dev/null +++ b/kopete/plugins/alias/aliaspreferences.cpp @@ -0,0 +1,502 @@ +/*************************************************************************** + * * + * 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 <kpushbutton.h> +#include <klistview.h> +#include <klocale.h> +#include <klineedit.h> +#include <kglobal.h> +#include <kgenericfactory.h> +#include <kmessagebox.h> +#include <kconfig.h> +#include <qregexp.h> +#include <qlayout.h> +#include <kplugininfo.h> +#include <kiconloader.h> +#include <qpainter.h> + +#include "kopetecommandhandler.h" +#include "kopetepluginmanager.h" +#include "kopeteaccount.h" +#include "kopeteprotocol.h" + +#include "aliasdialogbase.h" +#include "editaliasdialog.h" +#include "aliaspreferences.h" + +typedef KGenericFactory<AliasPreferences> AliasPreferencesFactory; + +class AliasItem : public QListViewItem +{ + public: + AliasItem( QListView *parent, + uint number, + const QString &alias, + const QString &command, const ProtocolList &p ) : + QListViewItem( parent, alias, command ) + { + protocolList = p; + id = number; + } + + ProtocolList protocolList; + uint id; + + protected: + void paintCell( QPainter *p, const QColorGroup &cg, + int column, int width, int align ) + { + if ( column == 2 ) + { + int cellWidth = width - ( protocolList.count() * 16 ) - 4; + if ( cellWidth < 0 ) + cellWidth = 0; + + QListViewItem::paintCell( p, cg, column, cellWidth, align ); + + // Draw the rest of the background + QListView *lv = listView(); + if ( !lv ) + return; + + int marg = lv->itemMargin(); + int r = marg; + const BackgroundMode bgmode = lv->viewport()->backgroundMode(); + const QColorGroup::ColorRole crole = + QPalette::backgroundRoleFromMode( bgmode ); + p->fillRect( cellWidth, 0, width - cellWidth, height(), + cg.brush( crole ) ); + + if ( isSelected() && ( column == 0 || listView()->allColumnsShowFocus() ) ) + { + p->fillRect( QMAX( cellWidth, r - marg ), 0, + width - cellWidth - r + marg, height(), + cg.brush( QColorGroup::Highlight ) ); + if ( isEnabled() || !lv ) + p->setPen( cg.highlightedText() ); + else if ( !isEnabled() && lv ) + p->setPen( lv->palette().disabled().highlightedText() ); + } + + // And last, draw the online status icons + int mc_x = 0; + + for ( ProtocolList::Iterator it = protocolList.begin(); + it != protocolList.end(); ++it ) + { + QPixmap icon = SmallIcon( (*it)->pluginIcon() ); + p->drawPixmap( mc_x + 4, height() - 16, + icon ); + mc_x += 16; + } + } + else + { + // Use Qt's own drawing + QListViewItem::paintCell( p, cg, column, width, align ); + } + } +}; + +class ProtocolItem : public QListViewItem +{ + public: + ProtocolItem( QListView *parent, KPluginInfo *p ) : + QListViewItem( parent, p->name() ) + { + this->setPixmap( 0, SmallIcon( p->icon() ) ); + id = p->pluginName(); + } + + QString id; +}; + +K_EXPORT_COMPONENT_FACTORY( kcm_kopete_alias, AliasPreferencesFactory( "kcm_kopete_alias" ) ) + +AliasPreferences::AliasPreferences( QWidget *parent, const char *, const QStringList &args ) + : KCModule( AliasPreferencesFactory::instance(), parent, args ) +{ + ( new QVBoxLayout( this ) )->setAutoAdd( true ); + preferencesDialog = new AliasDialogBase( this ); + + connect( preferencesDialog->addButton, SIGNAL(clicked()), this, SLOT( slotAddAlias() ) ); + connect( preferencesDialog->editButton, SIGNAL(clicked()), this, SLOT( slotEditAlias() ) ); + connect( preferencesDialog->deleteButton, SIGNAL(clicked()), this, SLOT( slotDeleteAliases() ) ); + connect( Kopete::PluginManager::self(), SIGNAL( pluginLoaded( Kopete::Plugin * ) ), + this, SLOT( slotPluginLoaded( Kopete::Plugin * ) ) ); + + connect( preferencesDialog->aliasList, SIGNAL(selectionChanged()), + this, SLOT( slotCheckAliasSelected() ) ); + + load(); +} + +AliasPreferences::~AliasPreferences() +{ + QListViewItem *myChild = preferencesDialog->aliasList->firstChild(); + while( myChild ) + { + ProtocolList protocols = static_cast<AliasItem*>( myChild )->protocolList; + for( ProtocolList::Iterator it = protocols.begin(); it != protocols.end(); ++it ) + { + Kopete::CommandHandler::commandHandler()->unregisterAlias( + *it, + myChild->text(0) + ); + } + + myChild = myChild->nextSibling(); + } +} + +// reload configuration reading it from kopeterc +void AliasPreferences::load() +{ + KConfig *config = KGlobal::config(); + if( config->hasGroup( "AliasPlugin" ) ) + { + config->setGroup("AliasPlugin"); + QStringList aliases = config->readListEntry("AliasNames"); + for( QStringList::Iterator it = aliases.begin(); it != aliases.end(); ++it ) + { + uint aliasNumber = config->readUnsignedNumEntry( (*it) + "_id" ); + QString aliasCommand = config->readEntry( (*it) + "_command" ); + QStringList protocols = config->readListEntry( (*it) + "_protocols" ); + + ProtocolList protocolList; + for( QStringList::Iterator it2 = protocols.begin(); it2 != protocols.end(); ++it2 ) + { + Kopete::Plugin *p = Kopete::PluginManager::self()->plugin( *it2 ); + protocolList.append( (Kopete::Protocol*)p ); + } + + addAlias( *it, aliasCommand, protocolList, aliasNumber ); + } + + } + + slotCheckAliasSelected(); +} + +void AliasPreferences::slotPluginLoaded( Kopete::Plugin *plugin ) +{ + Kopete::Protocol *protocol = static_cast<Kopete::Protocol*>( plugin ); + if( protocol ) + { + KConfig *config = KGlobal::config(); + if( config->hasGroup( "AliasPlugin" ) ) + { + config->setGroup("AliasPlugin"); + QStringList aliases = config->readListEntry("AliasNames"); + for( QStringList::Iterator it = aliases.begin(); it != aliases.end(); ++it ) + { + uint aliasNumber = config->readUnsignedNumEntry( (*it) + "_id" ); + QString aliasCommand = config->readEntry( (*it) + "_command" ); + QStringList protocols = config->readListEntry( (*it) + "_protocols" ); + + for( QStringList::iterator it2 = protocols.begin(); it2 != protocols.end(); ++it2 ) + { + if( *it2 == protocol->pluginId() ) + { + QPair<Kopete::Protocol*, QString> pr( protocol, *it ); + if( protocolMap.find( pr ) == protocolMap.end() ) + { + Kopete::CommandHandler::commandHandler()->registerAlias( + protocol, + *it, + aliasCommand, + QString::fromLatin1("Custom alias for %1").arg(aliasCommand), + Kopete::CommandHandler::UserAlias + ); + + protocolMap.insert( pr, true ); + + AliasItem *item = aliasMap[ *it ]; + if( item ) + { + item->protocolList.append( protocol ); + item->repaint(); + } + else + { + ProtocolList pList; + pList.append( protocol ); + aliasMap.insert( *it, new AliasItem( preferencesDialog->aliasList, aliasNumber, *it, aliasCommand, pList ) ); + } + } + } + } + } + } + } +} + +// save list to kopeterc and creates map out of it +void AliasPreferences::save() +{ + KConfig *config = KGlobal::config(); + config->deleteGroup( QString::fromLatin1("AliasPlugin") ); + config->setGroup( QString::fromLatin1("AliasPlugin") ); + + QStringList aliases; + AliasItem *item = (AliasItem*)preferencesDialog->aliasList->firstChild(); + while( item ) + { + QStringList protocols; + for( ProtocolList::Iterator it = item->protocolList.begin(); + it != item->protocolList.end(); ++it ) + { + protocols += (*it)->pluginId(); + } + + aliases += item->text(0); + + config->writeEntry( item->text(0) + "_id", item->id ); + config->writeEntry( item->text(0) + "_command", item->text(1) ); + config->writeEntry( item->text(0) + "_protocols", protocols ); + + item = (AliasItem*)item->nextSibling(); + } + + config->writeEntry( "AliasNames", aliases ); + config->sync(); + emit KCModule::changed(false); +} + +void AliasPreferences::addAlias( QString &alias, QString &command, const ProtocolList &p, uint id ) +{ + QRegExp spaces( QString::fromLatin1("\\s+") ); + + if( alias.startsWith( QString::fromLatin1("/") ) ) + alias = alias.section( '/', 1 ); + if( command.startsWith( QString::fromLatin1("/") ) ) + command = command.section( '/', 1 ); + + if( id == 0 ) + { + if( preferencesDialog->aliasList->lastItem() ) + id = static_cast<AliasItem*>( preferencesDialog->aliasList->lastItem() )->id + 1; + else + id = 1; + } + + QString newAlias = command.section( spaces, 0, 0 ); + + aliasMap.insert( alias, new AliasItem( preferencesDialog->aliasList, id, alias, command, p ) ); + + // count the number of arguments present in 'command' + QRegExp rx( "(%\\d+)" ); + QStringList list; + int pos = 0; + while ( pos >= 0 ) { + pos = rx.search( command, pos ); + if ( pos > -1 ) { + list += rx.cap( 1 ); + pos += rx.matchedLength(); + } + } + int argc = list.count(); + + for( ProtocolList::ConstIterator it = p.begin(); it != p.end(); ++it ) + { + Kopete::CommandHandler::commandHandler()->registerAlias( + *it, + alias, + command, + QString::fromLatin1("Custom alias for %1").arg(command), + Kopete::CommandHandler::UserAlias, + 0, + argc + ); + + protocolMap.insert( QPair<Kopete::Protocol*,QString>( *it, alias ), true ); + } +} + +void AliasPreferences::slotAddAlias() +{ + EditAliasDialog addDialog; + loadProtocols( &addDialog ); + addDialog.addButton->setText( i18n("&Add") ); + + if( addDialog.exec() == QDialog::Accepted ) + { + QString alias = addDialog.alias->text(); + if( alias.startsWith( QString::fromLatin1("/") ) ) + alias = alias.section( '/', 1 ); + + if( alias.contains( QRegExp("[_=]") ) ) + { + KMessageBox::error( this, i18n("<qt>Could not add alias <b>%1</b>. An" + " alias name cannot contain the characters \"_\" or \"=\"." + "</qt>").arg(alias),i18n("Invalid Alias Name") ); + } + else + { + QString command = addDialog.command->text(); + ProtocolList protocols = selectedProtocols( &addDialog ); + + // Loop through selected protocols + + for( ProtocolList::Iterator it = protocols.begin(); it != protocols.end(); ++it ) + { + + // And check if they already have the command enabled + + if( Kopete::CommandHandler::commandHandler()->commandHandledByProtocol( alias, *it ) ) + { + KMessageBox::error( this, i18n("<qt>Could not add alias <b>%1</b>. This " + "command is already being handled by either another alias or " + "Kopete itself.</qt>").arg(alias), i18n("Could Not Add Alias") ); + return; + } + } + addAlias( alias, command, protocols ); + emit KCModule::changed(true); + + } + } +} + +const ProtocolList AliasPreferences::selectedProtocols( EditAliasDialog *dialog ) +{ + ProtocolList protocolList; + QListViewItem *item = dialog->protocolList->firstChild(); + + while( item ) + { + if( item->isSelected() ) + { + + // If you dont have the selected protocol enabled, Kopete::PluginManager::self()->plugin + // will return NULL, check for that + + if(Kopete::PluginManager::self()->plugin( static_cast<ProtocolItem*>(item)->id) ) + protocolList.append( (Kopete::Protocol*) + Kopete::PluginManager::self()->plugin( static_cast<ProtocolItem*>(item)->id ) + ); + } + item = item->nextSibling(); + } + + return protocolList; +} + +void AliasPreferences::loadProtocols( EditAliasDialog *dialog ) +{ + QValueList<KPluginInfo*> plugins = Kopete::PluginManager::self()->availablePlugins("Protocols"); + for( QValueList<KPluginInfo*>::Iterator it = plugins.begin(); it != plugins.end(); ++it ) + { + ProtocolItem *item = new ProtocolItem( dialog->protocolList, *it ); + itemMap[ (Kopete::Protocol*)Kopete::PluginManager::self()->plugin( (*it)->pluginName() ) ] = item; + } +} + +void AliasPreferences::slotEditAlias() +{ + EditAliasDialog editDialog; + loadProtocols( &editDialog ); + + QListViewItem *item = preferencesDialog->aliasList->selectedItems().first(); + if( item ) + { + QString oldAlias = item->text(0); + editDialog.alias->setText( oldAlias ); + editDialog.command->setText( item->text(1) ); + ProtocolList protocols = static_cast<AliasItem*>( item )->protocolList; + for( ProtocolList::Iterator it = protocols.begin(); it != protocols.end(); ++it ) + { + itemMap[ *it ]->setSelected( true ); + } + + if( editDialog.exec() == QDialog::Accepted ) + { + QString alias = editDialog.alias->text(); + if( alias.startsWith( QString::fromLatin1("/") ) ) + alias = alias.section( '/', 1 ); + if( alias.contains( QRegExp("[_=]") ) ) + { + KMessageBox::error( this, i18n("<qt>Could not add alias <b>%1</b>. An" + " alias name cannot contain the characters \"_\" or \"=\"." + "</qt>").arg(alias),i18n("Invalid Alias Name") ); + } + else + { + QString command = editDialog.command->text(); + + if( alias == oldAlias ) + { + for( ProtocolList::Iterator it = protocols.begin(); it != protocols.end(); ++it ) + { + Kopete::CommandHandler::commandHandler()->unregisterAlias( + *it, + oldAlias + ); + } + + + ProtocolList selProtocols = selectedProtocols( &editDialog ); + + for( ProtocolList::Iterator it = selProtocols.begin(); it != selProtocols.end(); ++it ) + { + if( Kopete::CommandHandler::commandHandler()->commandHandledByProtocol( alias, *it ) ) + { + KMessageBox::error( this, i18n("<qt>Could not add alias <b>%1</b>. This " + "command is already being handled by either another alias or " + "Kopete itself.</qt>").arg(alias), i18n("Could Not Add Alias") ); + return; + } + } + + delete item; + + addAlias( alias, command, selProtocols ); + emit KCModule::changed(true); + } + } + } + } +} + +void AliasPreferences::slotDeleteAliases() +{ + if( KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete the selected aliases?"), i18n("Delete Aliases"), KGuiItem(i18n("Delete"), "editdelete") ) == KMessageBox::Continue ) + { + QPtrList< QListViewItem > items = preferencesDialog->aliasList->selectedItems(); + for( QListViewItem *i = items.first(); i; i = items.next() ) + { + ProtocolList protocols = static_cast<AliasItem*>( i )->protocolList; + for( ProtocolList::Iterator it = protocols.begin(); it != protocols.end(); ++it ) + { + Kopete::CommandHandler::commandHandler()->unregisterAlias( + *it, + i->text(0) + ); + + protocolMap.erase( QPair<Kopete::Protocol*,QString>( *it, i->text(0) ) ); + } + + aliasMap.erase( i->text(0) ); + delete i; + emit KCModule::changed(true); + } + + save(); + } +} + +void AliasPreferences::slotCheckAliasSelected() +{ + int numItems = preferencesDialog->aliasList->selectedItems().count(); + preferencesDialog->deleteButton->setEnabled( numItems > 0 ); + preferencesDialog->editButton->setEnabled( numItems == 1 ); +} + +#include "aliaspreferences.moc" + diff --git a/kopete/plugins/alias/aliaspreferences.h b/kopete/plugins/alias/aliaspreferences.h new file mode 100644 index 00000000..330553a3 --- /dev/null +++ b/kopete/plugins/alias/aliaspreferences.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef AliasPREFERENCES_H +#define AliasPREFERENCES_H + +#include "kcmodule.h" + +typedef QValueList<Kopete::Protocol*> ProtocolList; + +class AliasDialogBase; +namespace Kopete { class Protocol; } +class ProtocolItem; +class AliasItem; +class AliasDialog; +namespace Kopete { class Plugin; } + +class AliasPreferences : public KCModule +{ + Q_OBJECT + + public: + AliasPreferences( QWidget *parent = 0, const char *name = 0, + const QStringList &args = QStringList() ); + ~AliasPreferences(); + + virtual void save(); + virtual void load(); + + private slots: + void slotAddAlias(); + void slotEditAlias(); + void slotDeleteAliases(); + void slotCheckAliasSelected(); + void slotPluginLoaded( Kopete::Plugin * ); + + private: + AliasDialogBase * preferencesDialog; + void addAlias( QString &alias, QString &command, const ProtocolList &p, uint id = 0 ); + void loadProtocols( EditAliasDialog *dialog ); + const ProtocolList selectedProtocols( EditAliasDialog *dialog ); + QMap<Kopete::Protocol*,ProtocolItem*> itemMap; + QMap<QPair<Kopete::Protocol*,QString>, bool> protocolMap; + QMap<QString,AliasItem*> aliasMap; +}; + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/plugins/alias/editaliasdialog.cpp b/kopete/plugins/alias/editaliasdialog.cpp new file mode 100644 index 00000000..42eb2f4b --- /dev/null +++ b/kopete/plugins/alias/editaliasdialog.cpp @@ -0,0 +1,51 @@ +/* + Kopete Alias Plugin + + Copyright (c) 2005 by Matt Rogers <[email protected]> + Kopete Copyright (c) 2002-2005 by the Kopete Developers <[email protected]> + + *************************************************************************** + * * + * 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 "editaliasdialog.h" +#include <qobject.h> +#include <kpushbutton.h> +#include <qwidget.h> +#include <qstring.h> +#include <klineedit.h> +#include <klistview.h> + + +EditAliasDialog::EditAliasDialog( QWidget* parent, const char* name ) +: AliasDialog( parent, name ) +{ + QObject::connect( alias, SIGNAL( textChanged( const QString& ) ), this, SLOT( checkButtonsEnabled() ) ); + QObject::connect( command, SIGNAL( textChanged( const QString& ) ), this, SLOT( checkButtonsEnabled() ) ); + QObject::connect( protocolList, SIGNAL( selectionChanged() ), this, SLOT( checkButtonsEnabled() ) ); + + checkButtonsEnabled(); +} + +EditAliasDialog::~EditAliasDialog() +{ +} + +void EditAliasDialog::checkButtonsEnabled() +{ + if ( !alias->text().isEmpty() && !command->text().isEmpty() && !protocolList->selectedItems().isEmpty() ) + addButton->setEnabled( true ); + else + addButton->setEnabled( false ) ; +} + +#include "editaliasdialog.moc" + +// kate: space-indent off; replace-tabs off; tab-width 4; indent-mode csands; diff --git a/kopete/plugins/alias/editaliasdialog.h b/kopete/plugins/alias/editaliasdialog.h new file mode 100644 index 00000000..869e8903 --- /dev/null +++ b/kopete/plugins/alias/editaliasdialog.h @@ -0,0 +1,38 @@ +/* + Kopete Alias Plugin + + Copyright (c) 2005 by Matt Rogers <[email protected]> + Kopete Copyright (c) 2002-2005 by the Kopete Developers <[email protected]> + + *************************************************************************** + * * + * 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. * + * * + *************************************************************************** + +*/ + +#ifndef _EDITALIASDIALOG_H_ +#define _EDITALIASDIALOG_H_ + +#include "aliasdialog.h" + +class QWidget; + +class EditAliasDialog : public AliasDialog +{ + Q_OBJECT +public: + EditAliasDialog( QWidget* parent = 0, const char* name = 0 ); + virtual ~EditAliasDialog(); + +public slots: + void checkButtonsEnabled(); +}; + +#endif + +// kate: space-indent off; replace-tabs off; tab-width 4; indent-mode csands; diff --git a/kopete/plugins/alias/kopete_alias.desktop b/kopete/plugins/alias/kopete_alias.desktop new file mode 100644 index 00000000..4a23fcd3 --- /dev/null +++ b/kopete/plugins/alias/kopete_alias.desktop @@ -0,0 +1,108 @@ +[Desktop Entry] +Type=Service +X-Kopete-Version=1000900 +Icon=alias +ServiceTypes=Kopete/Plugin +X-KDE-Library=kopete_alias +X-KDE-PluginInfo-Author=Jason Keirstead +X-KDE-PluginInfo-Name=kopete_alias +X-KDE-PluginInfo-Version=0.8.0 +X-KDE-PluginInfo-Website=http://kopete.kde.org +X-KDE-PluginInfo-Category=Plugins +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +Name=Alias +Name[ar]=اسم مستعار +Name[be]=Псеўданім +Name[bg]=Запазени думи +Name[bn]=ছদ্মনাম +Name[br]=Lesanv +Name[ca]=Àlies +Name[cy]=Ffugenw +Name[el]=Αντιστοιχία +Name[eo]=Alinomo +Name[eu]=Aliasa +Name[fa]=نامگردان +Name[fi]=Uusi nimi +Name[ga]=Ailias +Name[he]=כינוי +Name[hi]=अलाएस +Name[hu]=Alias nevek +Name[is]=Samheiti +Name[ja]=エイリアス +Name[ka]=ფსევდონიმი +Name[kk]=Бүркеншік атаулар +Name[km]=ឈ្មោះក្លែងក្លាយ +Name[lt]=Kitas vardas +Name[mk]=Други имиња +Name[ne]=उपनाम +Name[pa]=ਉਪ-ਨਾਂ +Name[pt]=Nome Alternativo +Name[pt_BR]=Apelidos +Name[ru]=Псевдоним +Name[sl]=Drugo ime +Name[sr]=Алијас +Name[sr@Latn]=Alijas +Name[ta]=மாற்றுப்பெயர் +Name[tg]=Тахаллус +Name[tr]=Takma İsim +Name[uk]=Псевдонім +Name[zh_CN]=别名 +Name[zh_HK]=別名 +Name[zh_TW]=別名 +Comment=Adds custom aliases for commands +Comment[ar]=يضيف أسماء مستعارة للأوامر +Comment[be]=Дадаць адмысловыя псеўданімы для загадаў +Comment[bg]=Приставка за добавяне на запазени думи, при въвеждането на които ще се изпълняват зададени команди +Comment[bn]=কম্যান্ডের জন্য স্বনির্বাচিত ছদ্মনাম যোগ করে +Comment[bs]=Dodajte vlastite aliase naredbama +Comment[ca]=Afegeix àlies personalitzats als vostres comandaments +Comment[cs]=Přidává vlastní přezdívky pro příkazy +Comment[cy]=Ychwanegu ffugenwau addasiedig ar gyfer gorchmynion +Comment[da]=Tilføj personligt alias for kommandoer +Comment[de]=Fügt benutzerdefinierte Aliase für Befehle hinzu +Comment[el]=Προσθέτει προσαρμοσμένες αντιστοιχίες για εντολές +Comment[es]=Añade alias personales a las órdenes +Comment[et]=Lisab käskudele kohandatud aliase +Comment[eu]=Alias pertsonalizatuak gehitzen ditu aginduentzat +Comment[fa]=نامگردانهای سفارشی را برای فرمانها میافزاید +Comment[fi]=Lisää uusia nimiä komennoille +Comment[fr]=Ajoute des alias personnalisés à des commandes +Comment[gl]=Engadir alias persoáis para comandos +Comment[he]=הוספת כינוים מותאמים אישית עבור פקודות +Comment[hi]=कमांड्स के लिए मनपसंद अलाएस जोड़े +Comment[hr]=Dodaje posebne aliase za naredbe +Comment[hu]=Egyéni másodlagos (alias) nevek megadása parancsokhoz +Comment[is]=Bætir við samheitum á skipanir +Comment[it]=Aggiungi alias personalizzati per i comandi +Comment[ja]=コマンドのカスタムエイリアスを追加 +Comment[ka]=ბრძანებებს ანიჭებს სხვადასხვა ფსევდონიმებს +Comment[kk]=Командаларға бүркеншік атауларды беру +Comment[km]=បន្ថែមឈ្មោះក្លែងក្លាយផ្ទាល់ខ្លួនសម្រាប់ពាក្យបញ្ជា +Comment[lt]=Komandoms suteikiami papildomi vardai +Comment[mk]=Додава сопствени алтернативни имиња на командите +Comment[nb]=Legg til egne alias for kommandoer +Comment[nds]=Föögt egen Aliases för Befehlen to +Comment[ne]=आदेशका लागि अनुकूल उपनामहरू थप्दछ +Comment[nl]=Toevoegen van eigen aliassen voor commando's +Comment[nn]=Legg til eigne alias for kommandoar +Comment[pl]=Dodawanie własnych aliasów dla poleceń +Comment[pt]=Adiciona novos nomes para os comandos +Comment[pt_BR]=Adiciona notas pessoais em seus contatos +Comment[ru]=Добавляет псевдонимы для команд +Comment[se]=Lasit iežat aliasaid gohččumiid várás +Comment[sk]=Pridá vlastné aliasy pre príkazy +Comment[sl]=Dodajanje drugih imen za ukaze +Comment[sr]=Додаје посебне алијасе за наредбе +Comment[sr@Latn]=Dodaje posebne alijase za naredbe +Comment[sv]=Lägger till egna alias för kommandon +Comment[ta]=கட்டளைகள் தன் விருப்பப் பெயரை சேர்க்கும் +Comment[tg]=Барои фармонҳо тахаллусҳои дигарро илова мекунад +Comment[tr]=Komutlar için özel takma isimler ekler +Comment[uk]=Додає псевдоніми для команд +Comment[zh_CN]=添加命令的自定义别名 +Comment[zh_HK]=為命令加上自訂別名 +Comment[zh_TW]=新增命令的別名 + diff --git a/kopete/plugins/alias/kopete_alias_config.desktop b/kopete/plugins/alias/kopete_alias_config.desktop new file mode 100644 index 00000000..01fadd24 --- /dev/null +++ b/kopete/plugins/alias/kopete_alias_config.desktop @@ -0,0 +1,104 @@ +[Desktop Entry] +Icon=color +Type=Service +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kopete_alias +X-KDE-FactoryName=AliasConfigFactory +X-KDE-ParentApp=kopete_alias +X-KDE-ParentComponents=kopete_alias + +Name=Alias +Name[ar]=اسم مستعار +Name[be]=Псеўданім +Name[bg]=Запазени думи +Name[bn]=ছদ্মনাম +Name[br]=Lesanv +Name[ca]=Àlies +Name[cy]=Ffugenw +Name[el]=Αντιστοιχία +Name[eo]=Alinomo +Name[eu]=Aliasa +Name[fa]=نامگردان +Name[fi]=Uusi nimi +Name[ga]=Ailias +Name[he]=כינוי +Name[hi]=अलाएस +Name[hu]=Alias nevek +Name[is]=Samheiti +Name[ja]=エイリアス +Name[ka]=ფსევდონიმი +Name[kk]=Бүркеншік атаулар +Name[km]=ឈ្មោះក្លែងក្លាយ +Name[lt]=Kitas vardas +Name[mk]=Други имиња +Name[ne]=उपनाम +Name[pa]=ਉਪ-ਨਾਂ +Name[pt]=Nome Alternativo +Name[pt_BR]=Apelidos +Name[ru]=Псевдоним +Name[sl]=Drugo ime +Name[sr]=Алијас +Name[sr@Latn]=Alijas +Name[ta]=மாற்றுப்பெயர் +Name[tg]=Тахаллус +Name[tr]=Takma İsim +Name[uk]=Псевдонім +Name[zh_CN]=别名 +Name[zh_HK]=別名 +Name[zh_TW]=別名 +Comment=Adds custom aliases for commands +Comment[ar]=يضيف أسماء مستعارة للأوامر +Comment[be]=Дадаць адмысловыя псеўданімы для загадаў +Comment[bg]=Приставка за добавяне на запазени думи, при въвеждането на които ще се изпълняват зададени команди +Comment[bn]=কম্যান্ডের জন্য স্বনির্বাচিত ছদ্মনাম যোগ করে +Comment[bs]=Dodajte vlastite aliase naredbama +Comment[ca]=Afegeix àlies personalitzats als vostres comandaments +Comment[cs]=Přidává vlastní přezdívky pro příkazy +Comment[cy]=Ychwanegu ffugenwau addasiedig ar gyfer gorchmynion +Comment[da]=Tilføj personligt alias for kommandoer +Comment[de]=Fügt benutzerdefinierte Aliase für Befehle hinzu +Comment[el]=Προσθέτει προσαρμοσμένες αντιστοιχίες για εντολές +Comment[es]=Añade alias personales a las órdenes +Comment[et]=Lisab käskudele kohandatud aliase +Comment[eu]=Alias pertsonalizatuak gehitzen ditu aginduentzat +Comment[fa]=نامگردانهای سفارشی را برای فرمانها میافزاید +Comment[fi]=Lisää uusia nimiä komennoille +Comment[fr]=Ajoute des alias personnalisés à des commandes +Comment[gl]=Engadir alias persoáis para comandos +Comment[he]=הוספת כינוים מותאמים אישית עבור פקודות +Comment[hi]=कमांड्स के लिए मनपसंद अलाएस जोड़े +Comment[hr]=Dodaje posebne aliase za naredbe +Comment[hu]=Egyéni másodlagos (alias) nevek megadása parancsokhoz +Comment[is]=Bætir við samheitum á skipanir +Comment[it]=Aggiungi alias personalizzati per i comandi +Comment[ja]=コマンドのカスタムエイリアスを追加 +Comment[ka]=ბრძანებებს ანიჭებს სხვადასხვა ფსევდონიმებს +Comment[kk]=Командаларға бүркеншік атауларды беру +Comment[km]=បន្ថែមឈ្មោះក្លែងក្លាយផ្ទាល់ខ្លួនសម្រាប់ពាក្យបញ្ជា +Comment[lt]=Komandoms suteikiami papildomi vardai +Comment[mk]=Додава сопствени алтернативни имиња на командите +Comment[nb]=Legg til egne alias for kommandoer +Comment[nds]=Föögt egen Aliases för Befehlen to +Comment[ne]=आदेशका लागि अनुकूल उपनामहरू थप्दछ +Comment[nl]=Toevoegen van eigen aliassen voor commando's +Comment[nn]=Legg til eigne alias for kommandoar +Comment[pl]=Dodawanie własnych aliasów dla poleceń +Comment[pt]=Adiciona novos nomes para os comandos +Comment[pt_BR]=Adiciona notas pessoais em seus contatos +Comment[ru]=Добавляет псевдонимы для команд +Comment[se]=Lasit iežat aliasaid gohččumiid várás +Comment[sk]=Pridá vlastné aliasy pre príkazy +Comment[sl]=Dodajanje drugih imen za ukaze +Comment[sr]=Додаје посебне алијасе за наредбе +Comment[sr@Latn]=Dodaje posebne alijase za naredbe +Comment[sv]=Lägger till egna alias för kommandon +Comment[ta]=கட்டளைகள் தன் விருப்பப் பெயரை சேர்க்கும் +Comment[tg]=Барои фармонҳо тахаллусҳои дигарро илова мекунад +Comment[tr]=Komutlar için özel takma isimler ekler +Comment[uk]=Додає псевдоніми для команд +Comment[zh_CN]=添加命令的自定义别名 +Comment[zh_HK]=為命令加上自訂別名 +Comment[zh_TW]=新增命令的別名 + |