Commit bf10f9c6 authored by Christian Christiansen's avatar Christian Christiansen Committed by Peter Simonsson

Allow channel history to be deleted

Summary:
Any channel which has ever been attempted to be joined is currently
saved to history, including unsuccessful attempts and typos. These
can be seen in the join channel dialog (Ctrl+J).

The only way previously for a channel to be deleted from history
was to manually edit ~/.config/konversationrc

This is now rectified, with a delete button in the join channel
dialog, enabling users to delete previously selected channels from
history.

Reviewers: #konversation, psn

Reviewed By: #konversation, psn

Subscribers: #konversation

Tags: #konversation

Differential Revision: https://phabricator.kde.org/D28644
parent 0a1ec76d
......@@ -20,6 +20,9 @@
#include <KConfigGroup>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <KMessageBox>
#include <KStandardGuiItem>
namespace Konversation
{
......@@ -47,6 +50,9 @@ namespace Konversation
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<Server *> serverList = Application::instance()->getConnectionManager()->getServerList();
foreach (Server *server, serverList)
......@@ -190,10 +196,18 @@ namespace Konversation
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 @@ namespace Konversation
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();
}
}
}
......@@ -42,6 +42,7 @@ namespace Konversation
void slotSelectedConnectionChanged(int);
void slotChannelChanged(const QString& text);
void slotChannelHistoryCleared();
void deleteChannel();
private:
Ui::JoinChannelUI m_ui;
......
......@@ -17,7 +17,16 @@ the Free Software Foundation; either version 2 of the License, or
</rect>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
......@@ -36,7 +45,7 @@ the Free Software Foundation; either version 2 of the License, or
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="2">
<widget class="KHistoryComboBox" name="channelCombo">
<property name="autoCompletion">
<bool>true</bool>
......@@ -46,10 +55,22 @@ the Free Software Foundation; either version 2 of the License, or
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KLineEdit" name="passwordEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
<item row="0" column="0">
<widget class="QLabel" name="textLabel8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Connection:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
......@@ -69,28 +90,44 @@ the Free Software Foundation; either version 2 of the License, or
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="textLabel8">
<item row="1" column="3">
<widget class="QPushButton" name="delBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Connection:</string>
<property name="minimumSize">
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="toolTip">
<string>Remove</string>
</property>
<property name="wordWrap">
<bool>false</bool>
<property name="icon">
<iconset theme="edit-delete"/>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2" colspan="2">
<widget class="KComboBox" name="networkNameCombo"/>
</item>
<item row="2" column="2" colspan="2">
<widget class="KLineEdit" name="passwordEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
......@@ -119,7 +156,6 @@ the Free Software Foundation; either version 2 of the License, or
<includes>
<include location="local">kcombobox.h</include>
<include location="local">klineedit.h</include>
<include location="local">klineedit.h</include>
</includes>
<resources/>
<connections/>
......
......@@ -138,6 +138,11 @@ namespace Konversation
m_channelList.removeAll(channel);
}
void ServerGroupSettings::removeChannelFromHistory(const ChannelSettings& channel)
{
m_channelHistory.removeAll(channel);
}
IdentityPtr ServerGroupSettings::identity() const
{
return Preferences::identityById(m_identityId);
......
......@@ -100,6 +100,7 @@ namespace Konversation
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment