diff --git a/src/irc/joinchanneldialog.h b/src/irc/joinchanneldialog.h --- a/src/irc/joinchanneldialog.h +++ b/src/irc/joinchanneldialog.h @@ -42,6 +42,7 @@ void slotSelectedConnectionChanged(int); void slotChannelChanged(const QString& text); void slotChannelHistoryCleared(); + void deleteChannel(); private: Ui::JoinChannelUI m_ui; diff --git a/src/irc/joinchanneldialog.cpp b/src/irc/joinchanneldialog.cpp --- a/src/irc/joinchanneldialog.cpp +++ b/src/irc/joinchanneldialog.cpp @@ -20,6 +20,9 @@ #include #include #include +#include +#include + namespace Konversation { @@ -47,6 +50,9 @@ mOkButton->setEnabled(false); connect(m_ui.channelCombo, &KHistoryComboBox::editTextChanged, this, &JoinChannelDialog::slotChannelChanged); + m_ui.delBtn->setEnabled(false); + connect(m_ui.delBtn, &QPushButton::clicked, this, &JoinChannelDialog::deleteChannel); + // Add network names to network combobox and select the one corresponding to argument. QList serverList = Application::instance()->getConnectionManager()->getServerList(); foreach (Server *server, serverList) @@ -190,10 +196,18 @@ void JoinChannelDialog::slotChannelChanged(const QString& text) { + QStringList history = m_ui.channelCombo->historyItems(); + if (history.contains(text) && !text.isEmpty()) + { + m_ui.delBtn->setEnabled(true); + } + else + { + m_ui.delBtn->setEnabled(false); + } mOkButton->setEnabled(!text.isEmpty()); } - void JoinChannelDialog::slotChannelHistoryCleared() { int connectionId = m_ui.networkNameCombo->itemData(m_ui.networkNameCombo->currentIndex()).toInt(); @@ -202,5 +216,28 @@ if (server && server->getServerGroup()) server->getServerGroup()->clearChannelHistory(); } + + void JoinChannelDialog::deleteChannel() + { + QString channel = m_ui.channelCombo->currentText(); + QString warningTxt = i18n("Are you sure you want to remove this channel from your history?"); + + if(KMessageBox::warningContinueCancel(this, warningTxt, i18n("Remove channel"), KStandardGuiItem::del()) == KMessageBox::Continue) + { + int connectionId = m_ui.networkNameCombo->itemData(m_ui.networkNameCombo->currentIndex()).toInt(); + Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); + + if (server && server->getServerGroup()) + { + Konversation::ChannelSettings channelSettings = server->getServerGroup()->channelByNameFromHistory(channel); + server->getServerGroup()->removeChannelFromHistory(channelSettings); + } + + m_ui.channelCombo->removeFromHistory(channel); + m_ui.channelCombo->clearEditText(); + + } + } + } diff --git a/src/irc/joinchannelui.ui b/src/irc/joinchannelui.ui --- a/src/irc/joinchannelui.ui +++ b/src/irc/joinchannelui.ui @@ -17,7 +17,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -36,7 +45,7 @@ - + true @@ -46,10 +55,22 @@ - - - - QLineEdit::Password + + + + + 0 + 0 + + + + Connection: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false @@ -69,28 +90,44 @@ - - + + - + 0 0 - - Connection: + + + 28 + 28 + - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + Remove - - false + + + + + + 16 + 16 + - + + + + + QLineEdit::Password + + + @@ -119,7 +156,6 @@ kcombobox.h klineedit.h - klineedit.h diff --git a/src/irc/servergroupsettings.h b/src/irc/servergroupsettings.h --- a/src/irc/servergroupsettings.h +++ b/src/irc/servergroupsettings.h @@ -100,6 +100,7 @@ void clearChannelHistory(); void setChannelHistory(const ChannelList& list) { m_channelHistory = list; } void appendChannelHistory(const ChannelSettings& channel); + void removeChannelFromHistory(const ChannelSettings& channel); ChannelList channelHistory() const { return m_channelHistory; } ChannelSettings channelByNameFromHistory(const QString& channelName); diff --git a/src/irc/servergroupsettings.cpp b/src/irc/servergroupsettings.cpp --- a/src/irc/servergroupsettings.cpp +++ b/src/irc/servergroupsettings.cpp @@ -138,6 +138,11 @@ m_channelList.removeAll(channel); } + void ServerGroupSettings::removeChannelFromHistory(const ChannelSettings& channel) + { + m_channelHistory.removeAll(channel); + } + IdentityPtr ServerGroupSettings::identity() const { return Preferences::identityById(m_identityId);