From 77dbc0944c6a626004095608483f504462975e60 Mon Sep 17 00:00:00 2001 From: arieder Date: Thu, 28 Aug 2008 17:40:50 +0000 Subject: [PATCH] begin my work on the IRC-protocol, making the editaccount dialog and the network config dialog a bit more functional. adding irc protocol again to the CMakeLists.txt as optional git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdenetwork@854029 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/CMakeLists.txt | 9 +- kopete/protocols/irc/CMakeLists.txt | 4 +- kopete/protocols/irc/irccontact.cpp | 2 +- kopete/protocols/irc/ircnetwork.cpp | 9 +- kopete/protocols/irc/ircnetwork.h | 1 + kopete/protocols/irc/ircprotocol.cpp | 8 +- kopete/protocols/irc/ui/irceditaccount.ui | 285 +++++------------- kopete/protocols/irc/ui/irceditaccountwidget.cpp | 17 +- kopete/protocols/irc/ui/networkconfig.ui | 87 +++--- kopete/protocols/irc/ui/networkconfigwidget.cpp | 367 ++++++++++++----------- kopete/protocols/irc/ui/networkconfigwidget.h | 13 +- 11 files changed, 333 insertions(+), 469 deletions(-) diff --git a/kopete/protocols/CMakeLists.txt b/kopete/protocols/CMakeLists.txt index a7fac72e6..9f5f59c98 100644 --- a/kopete/protocols/CMakeLists.txt +++ b/kopete/protocols/CMakeLists.txt @@ -18,7 +18,7 @@ option(WITH_winpopup "Enable Kopete winpopup protocol" ON) option(WITH_gadu "Enable Kopete Gadu-Gadu protocol" ON) option(WITH_jabber "Enable Kopete Jabber protocol" ON) option(WITH_bonjour "Enable Kopete Bonjour protocol" ON) -# option(WITH_irc "Enable Kopete IRC protocol" OFF) +option(WITH_irc "Enable Kopete IRC protocol" OFF) include_directories(${KOPETE_INCLUDES}) @@ -34,9 +34,10 @@ endif(WITH_yahoo) if(WITH_qq) add_subdirectory( qq ) endif(WITH_qq) -# if(WITH_irc) -# add_subdirectory( irc ) -# endif(WITH_irc) +if(WITH_irc) + message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}: WARNING: Building the irc plugin, even if it hasn't been completely ported yet") + add_subdirectory( irc ) +endif(WITH_irc) if(NOT WIN32) if(WITH_winpopup) add_subdirectory( winpopup ) diff --git a/kopete/protocols/irc/CMakeLists.txt b/kopete/protocols/irc/CMakeLists.txt index 70308ff25..645a67afb 100644 --- a/kopete/protocols/irc/CMakeLists.txt +++ b/kopete/protocols/irc/CMakeLists.txt @@ -15,7 +15,7 @@ set(kopeteirc_ui_SRCS ui/ircaddcontactpage.cpp # ui/ircdialogs.cpp ui/irceditaccountwidget.cpp -# ui/networkconfigwidget.cpp + ui/networkconfigwidget.cpp ) kde4_add_ui_files(kopeteirc_ui_SRCS @@ -42,7 +42,7 @@ set(kopete_irc_SRCS kde4_add_plugin(kopete_irc ${kopete_irc_SRCS}) -target_link_libraries(kopete_irc ${KDE4_KIO_LIBS} kopete kirc_client kirc ) +target_link_libraries(kopete_irc ${KDE4_KIO_LIBS} ${QT_QT3SUPPORT_LIBRARY} kopete kirc_client kirc ) install(TARGETS kopete_irc DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/kopete/protocols/irc/irccontact.cpp b/kopete/protocols/irc/irccontact.cpp index f0b7b93b4..98d040e24 100644 --- a/kopete/protocols/irc/irccontact.cpp +++ b/kopete/protocols/irc/irccontact.cpp @@ -65,7 +65,7 @@ IRCContact::IRCContact(IRCAccount *account, const KIrc::Entity::Ptr &entity, Met { Q_ASSERT(entity); - kDebug(14120) << entity->name(); + kDebug(14120) <<"Entity name: "<< entity->name(); d->entity = entity; diff --git a/kopete/protocols/irc/ircnetwork.cpp b/kopete/protocols/irc/ircnetwork.cpp index b09842cfa..6067ed7b9 100644 --- a/kopete/protocols/irc/ircnetwork.cpp +++ b/kopete/protocols/irc/ircnetwork.cpp @@ -53,6 +53,11 @@ const NetworkList &Networks::networks() const return d->networks; } +void Networks::setNetworks( const IRC::NetworkList& networks ) +{ + d->networks=networks; +} + void Networks::slotReadNetworks() { d->networks.clear(); @@ -60,7 +65,7 @@ void Networks::slotReadNetworks() QFile xmlFile( KStandardDirs::locate( "appdata", "ircnetworks.xml" ) ); xmlFile.open( QIODevice::ReadOnly ); -#if 0 + // FIXME QDomDocument doc; doc.setContent( &xmlFile ); @@ -107,7 +112,7 @@ void Networks::slotReadNetworks() d->networks.append(network); networkNode = networkNode.nextSibling().toElement(); } -#endif + xmlFile.close(); } diff --git a/kopete/protocols/irc/ircnetwork.h b/kopete/protocols/irc/ircnetwork.h index ff648e1b3..faef8ebd9 100644 --- a/kopete/protocols/irc/ircnetwork.h +++ b/kopete/protocols/irc/ircnetwork.h @@ -56,6 +56,7 @@ public: static IRC::Networks *self(); const IRC::NetworkList &networks() const; + void setNetworks( const IRC::NetworkList& networks ); public slots: void slotReadNetworks(); diff --git a/kopete/protocols/irc/ircprotocol.cpp b/kopete/protocols/irc/ircprotocol.cpp index 27998c744..48d1198a6 100644 --- a/kopete/protocols/irc/ircprotocol.cpp +++ b/kopete/protocols/irc/ircprotocol.cpp @@ -23,7 +23,7 @@ #include "irctransferhandler.h" #include "ksparser.h" -//#include "networkconfigwidget.h" +#include "networkconfigwidget.h" //#include "channellist.h" #include "ircaddcontactpage.h" //#include "ircguiclient.h" @@ -538,10 +538,10 @@ void IRCProtocol::slotRawCommand( const QString &args, ChatSession *manager ) void IRCProtocol::editNetworks(const QString &networkName) { -/* - IRCNetworkConfigWidget *netConf = new IRCNetworkConfigWidget(UI::Global::mainWidget(), Qt::WDestructiveClose); + + IRCNetworkConfigWidget *netConf = new IRCNetworkConfigWidget(UI::Global::mainWidget() ); + netConf->setAttribute( Qt::WA_DeleteOnClose ); netConf->editNetworks(networkName); netConf->show(); -*/ } diff --git a/kopete/protocols/irc/ui/irceditaccount.ui b/kopete/protocols/irc/ui/irceditaccount.ui index aafb98bbd..d2c4065ba 100644 --- a/kopete/protocols/irc/ui/irceditaccount.ui +++ b/kopete/protocols/irc/ui/irceditaccount.ui @@ -10,22 +10,10 @@ - + 10 - - 10 - - - 10 - - - 10 - - - 6 - - + 6 @@ -40,26 +28,22 @@ 0 + + + 0 + 0 + 659 + 420 + + B&asic Setup - + 8 - - 8 - - - 8 - - - 8 - - - 6 - - + 6 @@ -68,22 +52,10 @@ Account Information - + 0 - - 0 - - - 0 - - - 0 - - - 6 - - + 6 @@ -94,7 +66,7 @@ QSizePolicy::Expanding - + 392 20 @@ -206,7 +178,7 @@ - + &Edit... @@ -275,7 +247,7 @@ QSizePolicy::Expanding - + 20 150 @@ -286,26 +258,22 @@ + + + 0 + 0 + 100 + 30 + + C&onnection - + 8 - - 8 - - - 8 - - - 8 - - - 6 - - + 6 @@ -320,22 +288,10 @@ Connection Preferences - - 0 - - - 0 - - - 0 - - + 0 - - 6 - - + 6 @@ -343,16 +299,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -376,7 +323,7 @@ QSizePolicy::Expanding - + 141 20 @@ -424,22 +371,10 @@ Run the Following Commands on Connect - + 0 - - 0 - - - 0 - - - 0 - - - 0 - - + 0 @@ -463,16 +398,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -500,26 +426,22 @@ + + + 0 + 0 + 100 + 30 + + A&dvanced Configuration - - 8 - - + 8 - - 8 - - - 8 - - - 6 - - + 6 @@ -540,22 +462,10 @@ Custom CTCP Replies - - 0 - - + 0 - - 0 - - - 0 - - - 0 - - + 0 @@ -576,16 +486,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -632,22 +533,10 @@ Default Messages - - 0 - - - 0 - - + 0 - - 0 - - - 6 - - + 6 @@ -696,26 +585,22 @@ + + + 0 + 0 + 100 + 30 + + Windows - - 8 - - - 8 - - - 8 - - + 8 - - 6 - - + 6 @@ -723,7 +608,7 @@ Qt::Vertical - + 20 40 @@ -737,22 +622,10 @@ Message Destinations - - 10 - - - 10 - - - 10 - - + 10 - - 6 - - + 6 @@ -771,22 +644,10 @@ - - 0 - - + 0 - - 0 - - - 0 - - - 6 - - + 6 @@ -877,22 +738,10 @@ - - 0 - - + 0 - - 0 - - - 0 - - - 6 - - + 6 @@ -991,7 +840,7 @@ userName realName network - editButton_2 + editButton preferSSL autoConnect charset diff --git a/kopete/protocols/irc/ui/irceditaccountwidget.cpp b/kopete/protocols/irc/ui/irceditaccountwidget.cpp index 2bd534c12..cfa6a6f50 100644 --- a/kopete/protocols/irc/ui/irceditaccountwidget.cpp +++ b/kopete/protocols/irc/ui/irceditaccountwidget.cpp @@ -85,7 +85,7 @@ IRCEditAccountWidget::IRCEditAccountWidget(IRCAccount *ident, QWidget *parent) // mUserName->setValidator( new QRegExpValidator( QString::fromLatin1("^[^\\s]*$"), mUserName ) ); // mNickName->setValidator( new QRegExpValidator( QString::fromLatin1("^[^#+&][^\\s]*$"), mNickName ) ); // mAltNickname->setValidator( new QRegExpValidator( QString::fromLatin1("^[^#+&][^\\s]*$"), mAltNickname ) ); -#if 0 + KCharsets *c = KGlobal::charsets(); charset->addItems( c->availableEncodingNames() ); @@ -98,7 +98,6 @@ IRCEditAccountWidget::IRCEditAccountWidget(IRCAccount *ident, QWidget *parent) break; } } -#endif /* connect( commandList, SIGNAL( contextMenu( K3ListView *, QListViewItem *, const QPoint & ) ), this, SLOT( slotCommandContextMenu( K3ListView *, QListViewItem *, const QPoint & ) ) ); @@ -106,16 +105,19 @@ IRCEditAccountWidget::IRCEditAccountWidget(IRCAccount *ident, QWidget *parent) connect( ctcpList, SIGNAL( contextMenu( K3ListView *, QListViewItem *, const QPoint & ) ), this, SLOT( slotCtcpContextMenu( K3ListView *, QListViewItem *, const QPoint & ) ) ); +*/ connect( addButton, SIGNAL( clicked() ), this, SLOT( slotAddCommand() ) ); connect( editButton, SIGNAL( clicked() ), this, SLOT(slotEditNetworks() ) ); connect( addReply, SIGNAL( clicked() ), this, SLOT( slotAddCtcp() ) ); - connect( network, SIGNAL( activated( const QString & ) ), - this, SLOT( slotUpdateNetworkDescription( const QString &) ) ); + connect( network, SIGNAL( activated( const QString & ) ), + this, SLOT( slotUpdateNetworkDescription( const QString &) ) ); +//TODO: signal doesn't exist anymore +#if 0 connect( IRCProtocol::self(), SIGNAL( networkConfigUpdated( const QString & ) ), this, SLOT( slotUpdateNetworks( const QString & ) ) ); -*/ +#endif slotUpdateNetworks( QString() ); } @@ -136,11 +138,14 @@ struct NetNameComparator { void IRCEditAccountWidget::slotUpdateNetworks( const QString & selectedNetwork ) { + network->clear(); + kDebug()<<"updating networks. selected="<networks(); std::sort(networks.begin(), networks.end(), NetNameComparator()); + kDebug()<<"got "<addItem(net.name); @@ -156,7 +161,7 @@ void IRCEditAccountWidget::slotUpdateNetworks( const QString & selectedNetwork ) void IRCEditAccountWidget::slotEditNetworks() { -// IRCProtocol::self()->editNetworks(network->currentText()); + IRCProtocol::self()->editNetworks(network->currentText()); } void IRCEditAccountWidget::slotUpdateNetworkDescription( const QString &network ) diff --git a/kopete/protocols/irc/ui/networkconfig.ui b/kopete/protocols/irc/ui/networkconfig.ui index 098735e82..62be86e52 100644 --- a/kopete/protocols/irc/ui/networkconfig.ui +++ b/kopete/protocols/irc/ui/networkconfig.ui @@ -13,22 +13,10 @@ Network Configuration - + 8 - - 8 - - - 8 - - - 8 - - - 6 - - + 6 @@ -43,22 +31,10 @@ Host Con&figurations - - 4 - - - 4 - - + 4 - - 4 - - - 6 - - + 6 @@ -95,7 +71,7 @@ QSizePolicy::Expanding - + 20 151 @@ -153,22 +129,10 @@ - - 5 - - + 5 - - 5 - - - 5 - - - 6 - - + 6 @@ -297,7 +261,7 @@ QSizePolicy::Expanding - + 260 20 @@ -348,5 +312,38 @@ m_cancelButton - + + + m_saveButton + clicked() + NetworkConfig + accept() + + + 563 + 515 + + + 347 + 268 + + + + + m_cancelButton + clicked() + NetworkConfig + reject() + + + 645 + 515 + + + 347 + 268 + + + + diff --git a/kopete/protocols/irc/ui/networkconfigwidget.cpp b/kopete/protocols/irc/ui/networkconfigwidget.cpp index 6b3b63315..811aee3bf 100644 --- a/kopete/protocols/irc/ui/networkconfigwidget.cpp +++ b/kopete/protocols/irc/ui/networkconfigwidget.cpp @@ -23,8 +23,6 @@ #include "irceditaccountwidget.h" #include "irctransferhandler.h" -#include "kircengine.h" - #include "kopeteaccountmanager.h" #include "kopetechatsessionmanager.h" #include "kopetecommandhandler.h" @@ -64,48 +62,51 @@ using namespace Kopete; class IRCNetworkConfigWidget::Private { public: - QList m_networks; + QMap m_networks; QString m_uiCurrentNetworkSelection; - QString m_uiCurrentHostSelection; + int m_uiCurrentHostSelectionIndex; }; -IRCNetworkConfigWidget::IRCNetworkConfigWidget(QWidget *parent, Qt::WFlags flags) - : QWidget(parent, flags) +IRCNetworkConfigWidget::IRCNetworkConfigWidget(QWidget *parent, Qt::WindowFlags flags) + : QDialog(parent, flags), + d( new IRCNetworkConfigWidget::Private ) { // kDebug(14120) ; + setupUi( this ); - m_networks = IRCNetworkList::self()->networks(); + foreach( const IRC::Network& net, IRC::Networks::self()->networks() ) + { + d->m_networks.insert( net.name, net ); + } - m_host->setValidator( new QRegExpValidator( QString::fromLatin1("^[\\w-\\.]*$"), this ) ); - upButton->setIconSet( SmallIconSet( "go-up" ) ); - downButton->setIconSet( SmallIconSet( "go-down" ) ); +// m_host->setValidator( new QRegExpValidator( QString::fromLatin1("^[\\w-\\.]*$"), this ) ); + upButton->setIcon( KIcon( "go-up" ) ); + downButton->setIcon( KIcon( "go-down" ) ); - connect(networkList, SIGNAL(selectionChanged()), + connect(m_networkList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkConfig())); - connect(hostList, SIGNAL(selectionChanged()), + connect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); connect(this, SIGNAL(accepted()), this, SLOT(slotSaveNetworkConfig())); - connect(this, SIGNAL(rejected()), - this, SLOT(slotReadNetworks())); connect(upButton, SIGNAL(clicked()), this, SLOT(slotMoveServerUp())); connect(downButton, SIGNAL(clicked()), this, SLOT(slotMoveServerDown())); - connect(newNetwork, SIGNAL(clicked()), + connect(m_newNetworkButton, SIGNAL(clicked()), this, SLOT(slotNewNetwork())); - connect(renameNetwork, SIGNAL(clicked()), + connect(m_renameNetworkButton, SIGNAL(clicked()), this, SLOT(slotRenameNetwork())); - connect(removeNetwork, SIGNAL(clicked()), + connect(m_removeNetworkButton, SIGNAL(clicked()), this, SLOT(slotDeleteNetwork())); - connect(removeHost, SIGNAL(clicked()), + connect(m_removeHost, SIGNAL(clicked()), this, SLOT(slotDeleteHost())); - connect(newHost, SIGNAL(clicked()), + connect(m_newHost, SIGNAL(clicked()), this, SLOT(slotNewHost())); connect(port, SIGNAL(valueChanged(int)), @@ -118,27 +119,27 @@ IRCNetworkConfigWidget::~IRCNetworkConfigWidget() void IRCNetworkConfigWidget::editNetworks(const QString &networkName) { - disconnect(networkList, SIGNAL(selectionChanged()), + disconnect(m_networkList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkConfig())); - disconnect(hostList, SIGNAL(selectionChanged()), + disconnect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); - networkList->clear(); + m_networkList->clear(); - for(Q3ValueList::ConstIterator it = m_networks.begin(); it != m_networks.end(); ++it) + foreach( const IRC::Network & net, d->m_networks) { - networkList->insertItem( (*it).name ); + m_networkList->insertItem( net.name ); } - networkList->sort(); + m_networkList->sort(); - connect(networkList, SIGNAL(selectionChanged()), + connect(m_networkList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkConfig())); - connect(hostList, SIGNAL(selectionChanged()), + connect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); if( !networkName.isEmpty() ) - networkList->setSelected(networkList->findItem(networkName), true); + m_networkList->setSelected(m_networkList->findItem(networkName), true); //slotUpdateNetworkConfig(); // unnecessary, setSelected emits selectionChanged } @@ -146,7 +147,7 @@ void IRCNetworkConfigWidget::editNetworks(const QString &networkName) void IRCNetworkConfigWidget::updateNetworkList() { networkList->clear(); - for(QValueList::ConstIterator it = m_networks.begin(); it != m_networks.end(); ++it) + for(QValueList::ConstIterator it = m_networks.begin(); it != m_networks.end(); ++it) networkList->insertItem( (*it).name ); networkList->sort(); @@ -156,204 +157,195 @@ void IRCNetworkConfigWidget::updateNetworkList() */ void IRCNetworkConfigWidget::slotUpdateNetworkConfig() { + kDebug(14120)<<"updating network config"; // update the data structure of the previous selection from the UI storeCurrentNetwork(); -/* + // update the UI from the data for the current selection - IRCNetwork *net = m_networks[ networkList->currentText() ]; - if (net) + + if (d->m_networks.contains( m_networkList->currentText() ) ) { - description->setText( net->description ); - hostList->clear(); + IRC::Network net=d->m_networks[ m_networkList->currentText() ]; + m_description->setText( net.description ); + m_hostList->clear(); + d->m_uiCurrentHostSelectionIndex=-1; - for( QValueList::Iterator it = net->hosts.begin(); it != net->hosts.end(); ++it ) - hostList->insertItem( (*it).host + QString::fromLatin1(":") + QString::number((*it).port) ); + for( QList::Iterator it = net.hosts.begin(); it != net.hosts.end(); ++it ) + m_hostList->insertItem( (*it).host + QString::fromLatin1(":") + QString::number((*it).port) ); // prevent nested event loop crash - disconnect(hostList, SIGNAL(selectionChanged()), + disconnect(m_hostList, SIGNAL(selectionChanged()), this, SLOT( slotUpdateNetworkHostConfig() ) ); - hostList->setSelected( 0, true ); + m_hostList->setSelected( 0, true ); slotUpdateNetworkHostConfig(); - connect(hostList, SIGNAL(selectionChanged()), + connect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); } // record the current selection - m_uiCurrentNetworkSelection = networkList->currentText(); -*/ + d->m_uiCurrentNetworkSelection = m_networkList->currentText(); + } void IRCNetworkConfigWidget::storeCurrentNetwork() { -/* - if ( !m_uiCurrentNetworkSelection.isEmpty() ) + if ( !d->m_uiCurrentNetworkSelection.isEmpty() ) { - IRCNetwork *net = m_networks[ m_uiCurrentNetworkSelection ]; - if ( net ) + if ( d->m_networks.contains( d->m_uiCurrentNetworkSelection ) ) { - net->description = description->text(); // crash on 2nd dialog show here! + d->m_networks[ d->m_uiCurrentNetworkSelection ].description = m_description->text(); // crash on 2nd dialog show here! } else - kDebug( 14120 ) << m_uiCurrentNetworkSelection << " was already gone from the cache!"; + { + kDebug( 14120 ) << d->m_uiCurrentNetworkSelection << " was already gone from the cache!"; + } } -*/ } void IRCNetworkConfigWidget::storeCurrentHost() { -/* - if ( !m_uiCurrentHostSelection.isEmpty() ) + if ( !d->m_uiCurrentNetworkSelection.isEmpty() && d->m_uiCurrentHostSelectionIndex!=-1 ) { - IRCHost *host = m_hosts[ m_uiCurrentHostSelection ]; - if ( host ) + kDebug( 14120 ) <<"storing host id= "<m_uiCurrentHostSelectionIndex; + IRC::Host &host = d->m_networks[ d->m_uiCurrentNetworkSelection ].hosts[ d->m_uiCurrentHostSelectionIndex ]; + kDebug( 14120 ) <<"old: "<text().isEmpty()) { - host->host = m_host->text(); - host->password = password->text(); - host->port = port->text().toInt(); - host->ssl = useSSL->isChecked(); + host.host = m_host->text(); +// host.password = password->text(); + host.port = port->text().toInt(); + host.ssl = useSSL->isChecked(); } + + kDebug( 14120 ) <<"new: "<text( d->m_uiCurrentHostSelectionIndex ) + QString::fromLatin1(":") + QString::number( value ); // changeItem causes a take() and insert, and we don't want a selectionChanged() signal that sets all this off again. - disconnect(hostList, SIGNAL(selectionChanged()), + disconnect(m_hostList, SIGNAL(selectionChanged()), this, SLOT( slotUpdateNetworkHostConfig() ) ); - hostList->changeItem(entryText, hostList->currentItem()); + m_hostList->changeItem(entryText, m_hostList->currentItem()); - connect(hostList, SIGNAL(selectionChanged()), + connect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); -*/ + } void IRCNetworkConfigWidget::slotUpdateNetworkHostConfig() { -/* storeCurrentHost(); - if (hostList->selectedItem()) + if (m_hostList->selectedItem()) { - m_uiCurrentHostSelection = hostList->currentText().section(':', 0, 0); - IRCHost *host = m_hosts[ m_uiCurrentHostSelection ]; + d->m_uiCurrentHostSelectionIndex = m_hostList->currentItem(); + int hostIndex=m_hostList->currentItem(); + kDebug(14120)<<"host index= "<< hostIndex; - if( host ) + if ( hostIndex < d->m_networks[ d->m_uiCurrentNetworkSelection ].hosts.size() ) { - m_host->setText( host->host ); - password->setText( host->password ); - port->setValue( host->port ); - useSSL->setChecked( host->ssl ); + IRC::Host host = d->m_networks[ d->m_uiCurrentNetworkSelection ].hosts[ hostIndex ]; + + m_host->setText( host.host ); + //password->setText( host.password ); + port->setValue( host.port ); + useSSL->setChecked( host.ssl ); - upButton->setEnabled(hostList->currentItem() > 0); - downButton->setEnabled(hostList->currentItem() < (int)(hostList->count()-1)); + upButton->setEnabled(m_hostList->currentItem() > 0); + downButton->setEnabled(m_hostList->currentItem() < (int)(m_hostList->count()-1)); } } else { - m_uiCurrentHostSelection = QString(); + d->m_uiCurrentHostSelectionIndex = -1; disconnect(port, SIGNAL(valueChanged(int)), this, SLOT( slotHostPortChanged( int ) ) ); m_host->clear(); - password->clear(); + //password->clear(); port->setValue( 6667 ); useSSL->setChecked( false ); connect(port, SIGNAL(valueChanged(int)), this, SLOT( slotHostPortChanged( int ) ) ); } -*/ } void IRCNetworkConfigWidget::slotDeleteNetwork() { -/* - QString network = networkList->currentText(); + QString network = m_networkList->currentText(); if( KMessageBox::warningContinueCancel( UI::Global::mainWidget(), i18n("Are you sure you want to delete the network %1?
" "Any accounts which use this network will have to be modified.
") .arg(network), i18n("Deleting Network"), - KGuiItem(i18n("&Delete Network"),"edit-delete"), QString::fromLatin1("AskIRCDeleteNetwork") ) == KMessageBox::Continue ) + KGuiItem(i18n("&Delete Network"),"edit-delete"), KStandardGuiItem::cancel(), QString::fromLatin1("AskIRCDeleteNetwork") ) == KMessageBox::Continue ) { - IRCNetwork *net = m_networks[ network ]; -// m_networks.remove( network ); -// delete net; - networkList->removeItem(networkList->currentItem()); + d->m_networks.remove( network ); + m_networkList->removeItem(m_networkList->currentItem()); slotUpdateNetworkHostConfig(); - } -*/ } void IRCNetworkConfigWidget::slotDeleteHost() { -/* QString hostName = m_host->text(); if ( KMessageBox::warningContinueCancel( UI::Global::mainWidget(), i18n("Are you sure you want to delete the host %1?") .arg(hostName), i18n("Deleting Host"), - KGuiItem(i18n("&Delete Host"),"edit-delete"), QString::fromLatin1("AskIRCDeleteHost")) == KMessageBox::Continue ) + KGuiItem(i18n("&Delete Host"),"edit-delete"), KStandardGuiItem::cancel(), QString::fromLatin1("AskIRCDeleteHost")) == KMessageBox::Continue ) { - IRCHost *host = m_hosts[ hostName ]; - if ( host ) + if ( m_hostList->selectedItem() ) { - disconnect(hostList, SIGNAL(selectionChanged()), + int hostIndex=m_hostList->currentItem(); + IRC::Host host = d->m_networks[d->m_uiCurrentNetworkSelection].hosts[hostIndex]; + disconnect(m_hostList, SIGNAL(selectionChanged()), this, SLOT( slotUpdateNetworkHostConfig() ) ); - QString entryText = host->host + QString::fromLatin1(":") + QString::number(host->port); - QListBoxItem * justAdded = hostList->findItem( entryText ); - hostList->removeItem(hostList->index(justAdded)); + m_hostList->removeItem(hostIndex); - connect(hostList, SIGNAL(selectionChanged()), + connect(m_hostList, SIGNAL(selectionChanged()), this, SLOT(slotUpdateNetworkHostConfig())); // remove from network as well - IRCNetwork *net = m_networks[ m_uiCurrentNetworkSelection ]; -// net->hosts.remove( host ); - - m_hosts.remove( host->host ); - delete host; + d->m_networks[ d->m_uiCurrentNetworkSelection ].hosts.removeAt(hostIndex); } } -*/ } void IRCNetworkConfigWidget::slotNewNetwork() { -/* + kDebug(14120)<<"Creating new network"; // create a new network struct - IRCNetwork *net = new IRCNetwork; + IRC::Network net; // give it the name of 'New Network' (incrementing number if needed) QString netName = QString::fromLatin1( "New Network" ); - if ( m_networks.find( netName ) ) + if ( d->m_networks.contains( netName ) ) { int newIdx = 1; do { netName = QString::fromLatin1( "New Network #%1" ).arg( newIdx++ ); } - while ( m_networks.find( netName ) && newIdx < 100 ); + while ( d->m_networks.contains( netName ) && newIdx < 100 ); if ( newIdx == 100 ) // pathological case return; } - net->name = netName; + net.name = netName; // and add it to the networks dict and list - m_networks.insert(net->name, net); - networkList->insertItem(net->name); - QListBoxItem * justAdded = networkList->findItem(net->name); - networkList->setSelected(justAdded, true); - networkList->setBottomItem(networkList->index(justAdded)); -*/ + d->m_networks.insert(net.name, net); + m_networkList->insertItem(net.name); + Q3ListBoxItem * justAdded = m_networkList->findItem(net.name); + m_networkList->setSelected(justAdded, true); + m_networkList->setBottomItem(m_networkList->index(justAdded)); } void IRCNetworkConfigWidget::slotNewHost() { -/* // create a new host - IRCHost *host = new IRCHost; + IRC::Host host; // prompt for a name bool ok; QString name = KInputDialog::getText( @@ -363,125 +355,134 @@ void IRCNetworkConfigWidget::slotNewHost() if ( ok ) { // dupe check - if ( m_hosts[ name ] ) + foreach( const IRC::Host & h, d->m_networks[d->m_uiCurrentNetworkSelection].hosts ) { - KMessageBox::sorry(this, i18n( "A host already exists with that name" ) ); - return; + if ( h.host == name ) //dupe found + { + KMessageBox::sorry(this, i18n( "A host already exists with that name" ) ); + return; + } } // set defaults on others - host->host = name; - host->port = 6667; - host->ssl = false; - // add it to the dict - m_hosts.insert( host->host, host ); + host.host = name; + host.port = 6667; + host.ssl = false; // add it to the network! - IRCNetwork *net = m_networks[networkList->currentText() ]; -// net->hosts.append( host ); + d->m_networks[ m_networkList->currentText() ].hosts.append( host ); // add it to the gui - QString entryText = host->host + QString::fromLatin1(":") + QString::number(host->port); - hostList->insertItem( entryText ); + QString entryText = host.host + QString::fromLatin1(":") + QString::number(host.port); + m_hostList->insertItem( entryText ); // select it in the gui - QListBoxItem * justAdded = hostList->findItem( entryText ); - hostList->setSelected( justAdded, true ); + Q3ListBoxItem * justAdded = m_hostList->findItem( entryText ); + m_hostList->setSelected( justAdded, true ); //hostList->setBottomItem(hostList->index(justAdded)); } -*/ } void IRCNetworkConfigWidget::slotRenameNetwork() { -/* - IRCNetwork *net = m_networks[ m_uiCurrentNetworkSelection ]; - if ( net ) + if ( d->m_networks.contains( d->m_uiCurrentNetworkSelection ) ) { + IRC::Network net =d-> m_networks[ d->m_uiCurrentNetworkSelection ]; bool ok; // popup up a dialog containing the current name QString name = KInputDialog::getText( i18n("Rename Network"), i18n("Enter the new name for this network:"), - m_uiCurrentNetworkSelection, &ok, + d->m_uiCurrentNetworkSelection, &ok, UI::Global::mainWidget() ); if ( ok ) { - if ( m_uiCurrentNetworkSelection != name ) + if ( d->m_uiCurrentNetworkSelection != name ) { // dupe check - if ( m_networks[ name ] ) + if ( d->m_networks.contains( name ) ) { KMessageBox::sorry(this, i18n( "A network already exists with that name" ) ); return; } - net->name = name; + net.name = name; + kDebug( 14120 )<<"changing name from "<m_uiCurrentNetworkSelection<<" to "<name, net ); - // ui - int idx = networkList->index(networkList->findItem(m_uiCurrentNetworkSelection)); - m_uiCurrentNetworkSelection = net->name; - networkList->changeItem( net->name, idx ); // changes the selection!!! - networkList->sort(); + d->m_networks.remove( d->m_uiCurrentNetworkSelection ); + d->m_networks.insert( net.name, net ); + + // ui + int idx = m_networkList->index(m_networkList->findItem(d->m_uiCurrentNetworkSelection)); + d->m_uiCurrentNetworkSelection = net.name; + m_networkList->changeItem( net.name, idx ); // changes the selection!!! + m_networkList->sort(); } } } -*/ } void IRCNetworkConfigWidget::slotMoveServerUp() { -/* - IRCHost *selectedHost = m_hosts[hostList->currentText().section(':', 0, 0)]; - IRCNetwork *selectedNetwork = m_networks[networkList->currentText()]; - - if( !selectedNetwork || !selectedHost ) - return; + IRC::Network& selectedNetwork = d->m_networks[ m_networkList->currentText() ]; + IRC::Host selectedHost = selectedNetwork.hosts[ m_hostList->currentItem() ]; - QValueList::iterator pos = selectedNetwork->hosts.find( selectedHost ); - if( pos != selectedNetwork->hosts.begin() ) - { - QValueList::iterator lastPos = pos; - lastPos--; - selectedNetwork->hosts.insert( lastPos, selectedHost ); - selectedNetwork->hosts.remove( pos ); - } + //if( !selectedNetwork || !selectedHost ) + // return; - unsigned int currentPos = hostList->currentItem(); + unsigned int currentPos = m_hostList->currentItem(); if( currentPos > 0 ) { - hostList->removeItem( currentPos ); - kDebug(14121) << selectedHost->host; - hostList->insertItem( selectedHost->host, --currentPos ); - hostList->setSelected( currentPos, true ); + selectedNetwork.hosts.swap( m_hostList->currentItem(),m_hostList->currentItem()-1 ); + + disconnect(m_hostList, SIGNAL(selectionChanged()), + this, SLOT(slotUpdateNetworkHostConfig())); + + m_hostList->removeItem( currentPos ); + kDebug(14120) << selectedHost.host; + m_hostList->insertItem( selectedHost.host, --currentPos ); + m_hostList->setSelected( currentPos, true ); + d->m_uiCurrentHostSelectionIndex=currentPos; + + connect(m_hostList, SIGNAL(selectionChanged()), + this, SLOT(slotUpdateNetworkHostConfig())); } -*/ } void IRCNetworkConfigWidget::slotMoveServerDown() { -/* - IRCHost *selectedHost = m_hosts[ hostList->currentText().section(':', 0, 0) ]; - IRCNetwork *selectedNetwork = m_networks[ networkList->currentText() ]; + IRC::Network& selectedNetwork = d->m_networks[ m_networkList->currentText() ]; + IRC::Host selectedHost = selectedNetwork.hosts[ m_hostList->currentItem() ]; - if( !selectedNetwork || !selectedHost ) - return; + //if( !selectedNetwork || !selectedHost ) + // return; - QValueList::Iterator pos = selectedNetwork->hosts.find( selectedHost ); - if( *pos != selectedNetwork->hosts.back() ) + unsigned int currentPos = m_hostList->currentItem(); + if( currentPos > 0 ) { - QValueList::Iterator nextPos = pos; - nextPos++; - selectedNetwork->hosts.insert( nextPos, selectedHost ); - selectedNetwork->hosts.remove( pos ); - } + selectedNetwork.hosts.swap( m_hostList->currentItem(),m_hostList->currentItem()-1 ); + + disconnect(m_hostList, SIGNAL(selectionChanged()), + this, SLOT(slotUpdateNetworkHostConfig())); - unsigned int currentPos = hostList->currentItem(); - if( currentPos < ( hostList->count() - 1 ) ) - { - hostList->removeItem( currentPos ); - hostList->insertItem( selectedHost->host, ++currentPos ); - hostList->setSelected( currentPos, true ); + m_hostList->removeItem( currentPos ); + kDebug(14120) << selectedHost.host; + m_hostList->insertItem( selectedHost.host, --currentPos ); + m_hostList->setSelected( currentPos, true ); + d->m_uiCurrentHostSelectionIndex=currentPos; + + connect(m_hostList, SIGNAL(selectionChanged()), + this, SLOT(slotUpdateNetworkHostConfig())); } -*/ } + +void IRCNetworkConfigWidget::slotSaveNetworkConfig() +{ + //HACK: remove the empty entry + d->m_networks.remove(QString()); + + IRC::NetworkList networks=d->m_networks.values(); //Convert from map to list + + IRC::Networks::self()->setNetworks(networks); + IRC::Networks::self()->slotSaveNetworkConfig(); +} + + #include "networkconfigwidget.moc" diff --git a/kopete/protocols/irc/ui/networkconfigwidget.h b/kopete/protocols/irc/ui/networkconfigwidget.h index 50916d76a..7f0832e9b 100644 --- a/kopete/protocols/irc/ui/networkconfigwidget.h +++ b/kopete/protocols/irc/ui/networkconfigwidget.h @@ -19,23 +19,25 @@ #ifndef IRCNETWORKCONFIGWIDGET_H #define IRCNETWORKCONFIGWIDGET_H -#include "networkconfig.h" +#include + +#include "ui_networkconfig.h" #include "ircnetwork.h" class IRCNetworkConfigWidget - : public QWidget, public NetworkConfig + : public QDialog, public Ui::NetworkConfig { Q_OBJECT public: - explicit IRCNetworkConfigWidget(QWidget *parent = 0, Qt::WFlags flags = 0); + explicit IRCNetworkConfigWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~IRCNetworkConfigWidget(); void editNetworks( const QString &networkName = QString() ); signals: - void networkSelected(const IRCNetwork &network); + void networkSelected(const IRC::Network &network); void networkConfigUpdated(const QString &selectedNetwork); @@ -52,6 +54,9 @@ private slots: void slotNewHost(); void slotHostPortChanged( int value ); // end of network list specific code + + //copies the altered informations to the global IRCNetworks List + void slotSaveNetworkConfig(); private: void storeCurrentNetwork(); -- 2.11.4.GIT