diff --git a/src/irc/joinchanneldialog.cpp b/src/irc/joinchanneldialog.cpp index 708622f2..424e46d5 100644 --- a/src/irc/joinchanneldialog.cpp +++ b/src/irc/joinchanneldialog.cpp @@ -1,206 +1,243 @@ /* 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. */ /* Copyright (C) 2004 by Peter Simonsson */ #include "joinchanneldialog.h" #include "application.h" #include "connectionmanager.h" #include "server.h" #include "channel.h" #include "servergroupsettings.h" #include #include #include #include +#include +#include + namespace Konversation { JoinChannelDialog::JoinChannelDialog(Server* server, QWidget *parent) : QDialog(parent) { setWindowTitle(i18n("Join Channel")); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(mainWidget); mOkButton = buttonBox->button(QDialogButtonBox::Ok); mOkButton->setDefault(true); mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::rejected, this, &JoinChannelDialog::reject); mOkButton->setDefault(true); setModal( true ); m_ui.setupUi(mainWidget); mainLayout->addWidget(mainWidget); mainLayout->addWidget(buttonBox); m_ui.channelCombo->setFocus(); 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) { m_ui.networkNameCombo->addItem(i18nc("network (nickname)", "%1 (%2)", server->getDisplayName(), server->getNickname()), server->connectionId()); connect(server, &Server::nicknameChanged, this, &JoinChannelDialog::slotNicknameChanged); } // Update channel history when selected connection changes connect(m_ui.networkNameCombo, static_cast(&KComboBox::currentIndexChanged), this, &JoinChannelDialog::slotSelectedConnectionChanged); // Clear channel history when the history combo box is cleared connect(m_ui.channelCombo, &KHistoryComboBox::cleared, this, &JoinChannelDialog::slotChannelHistoryCleared); // Preselect the current network m_ui.networkNameCombo->setCurrentIndex(m_ui.networkNameCombo->findData(server->connectionId())); // If the server is the first item, current index wont be changed // So channel history combo wont be populated, so force it slotSelectedConnectionChanged(m_ui.networkNameCombo->findData(server->connectionId())); connect(mOkButton, &QPushButton::clicked, this, &JoinChannelDialog::slotOk); connect(Application::instance()->getConnectionManager(), SIGNAL(connectionListChanged()), this, SLOT(slotConnectionListChanged())); } JoinChannelDialog::~JoinChannelDialog() { } int JoinChannelDialog::connectionId() const { return m_ui.networkNameCombo->itemData(m_ui.networkNameCombo->currentIndex()).toInt(); } QString JoinChannelDialog::channel() const { QString channel = m_ui.channelCombo->currentText(); if (!channel.isEmpty()) { int connectionId = m_ui.networkNameCombo->itemData(m_ui.networkNameCombo->currentIndex()).toInt(); Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); if (server && !server->isAChannel(channel)) channel = QLatin1Char('#') + channel; } return channel; } QString JoinChannelDialog::password() const { return m_ui.passwordEdit->text(); } void JoinChannelDialog::slotOk() { int connectionId = m_ui.networkNameCombo->itemData(m_ui.networkNameCombo->currentIndex()).toInt(); Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); // If the channel already exist in the history only the password will be updated. if (server && server->getServerGroup()) server->getServerGroup()->appendChannelHistory(ChannelSettings(channel(), password())); accept(); } void JoinChannelDialog::slotNicknameChanged(const QString& nickname) { Q_UNUSED(nickname); // Update all items QList serverList = Application::instance()->getConnectionManager()->getServerList(); foreach (Server *server, serverList) { int index = m_ui.networkNameCombo->findData(server->connectionId()); m_ui.networkNameCombo->setItemText(index, i18nc("network (nickname)", "%1 (%2)", server->getDisplayName(), server->getNickname())); } } void JoinChannelDialog::slotConnectionListChanged() { // Remove not-existing-anymore networks from the combobox for (int i = 0; i < m_ui.networkNameCombo->count(); i++) { int connectionId = m_ui.networkNameCombo->itemData(i).toInt(); Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); if (!server) { m_ui.networkNameCombo->removeItem(i); i--; } } // Add new network names to the combobox QList serverList = Application::instance()->getConnectionManager()->getServerList(); foreach (Server *server, serverList) { if (m_ui.networkNameCombo->findData(server->connectionId()) == -1) { m_ui.networkNameCombo->addItem(i18nc("network (nickname)", "%1 (%2)", server->getDisplayName(), server->getNickname()), server->connectionId()); connect(server, &Server::nicknameChanged, this, &JoinChannelDialog::slotNicknameChanged); } } } void JoinChannelDialog::slotSelectedConnectionChanged(int index) { m_ui.channelCombo->clear(); int connectionId = m_ui.networkNameCombo->itemData(index).toInt(); Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); if (server && server->getServerGroup()) { ChannelList history = server->getServerGroup()->channelHistory(); ChannelList::iterator endIt = history.end(); const QList &channels = server->getChannelList(); bool joined = false; // Append an empty string as first item QStringList channelHistory; channelHistory << QString(); for(ChannelList::iterator it = history.begin(); it != endIt; ++it) { // Don't add empty items to the combobox if ((*it).name().isEmpty()) continue; joined = false; foreach (Channel* chan, channels) { if(chan->getName() == (*it).name()) joined = true; } if(!joined) channelHistory << (*it).name(); } // Sort channel history for easier access channelHistory.sort(); // Set history items m_ui.channelCombo->setHistoryItems(channelHistory); } } 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(); Server *server = Application::instance()->getConnectionManager()->getServerByConnectionId(connectionId); 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/joinchanneldialog.h b/src/irc/joinchanneldialog.h index 731acab9..72d2ac0c 100644 --- a/src/irc/joinchanneldialog.h +++ b/src/irc/joinchanneldialog.h @@ -1,52 +1,53 @@ /* 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. */ /* Copyright (C) 2004 Peter Simonsson */ #ifndef KONVERSATIONJOINCHANNELDIALOG_H #define KONVERSATIONJOINCHANNELDIALOG_H #include #include "ui_joinchannelui.h" class Server; class QPushButton; namespace Konversation { class JoinChannelUI; class JoinChannelDialog : public QDialog { Q_OBJECT public: explicit JoinChannelDialog(Server* server, QWidget *parent = nullptr); ~JoinChannelDialog(); int connectionId() const; QString channel() const; QString password() const; protected Q_SLOTS: virtual void slotOk(); void slotNicknameChanged(const QString& nickname); void slotConnectionListChanged(); void slotSelectedConnectionChanged(int); void slotChannelChanged(const QString& text); void slotChannelHistoryCleared(); + void deleteChannel(); private: Ui::JoinChannelUI m_ui; QPushButton *mOkButton; }; } #endif diff --git a/src/irc/joinchannelui.ui b/src/irc/joinchannelui.ui index f0c4ee09..58b62fe2 100644 --- a/src/irc/joinchannelui.ui +++ b/src/irc/joinchannelui.ui @@ -1,126 +1,162 @@ (C) 2004 Peter Simonsson 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. JoinChannelUI 0 0 426 94 - + + 0 + + + 0 + + + 0 + + 0 C&hannel: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false channelCombo - + true true - - - - QLineEdit::Password + + + + + 0 + 0 + + + + Connection: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false &Password: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false passwordEdit - - + + - + 0 0 - - Connection: + + + 28 + 28 + - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + Remove - - false + + + + + + 16 + 16 + - + + + + + QLineEdit::Password + + + KLineEdit QLineEdit
klineedit.h
KComboBox QComboBox
kcombobox.h
KHistoryComboBox KComboBox
khistorycombobox.h
networkNameCombo channelCombo passwordEdit kcombobox.h klineedit.h - klineedit.h
diff --git a/src/irc/servergroupsettings.cpp b/src/irc/servergroupsettings.cpp index c2b98817..908d5124 100644 --- a/src/irc/servergroupsettings.cpp +++ b/src/irc/servergroupsettings.cpp @@ -1,220 +1,225 @@ /* 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. */ /* Copyright (C) 2004, 2007 Peter Simonsson Copyright (C) 2006-2008 Eike Hein */ #include "servergroupsettings.h" #include "application.h" namespace Konversation { int ServerGroupSettings::s_availableId = 0; ServerGroupSettings::ServerGroupSettings() : QSharedData() { m_id = s_availableId; s_availableId++; m_sortIndex = m_id; m_autoConnect = false; m_identityId = 0; m_enableNotifications = true; m_expanded = false; } ServerGroupSettings::ServerGroupSettings(int id) : QSharedData() { if(id < 0) { m_id = s_availableId; s_availableId++; } else { m_id = id; } m_sortIndex = m_id; m_autoConnect = false; m_identityId = 0; m_enableNotifications = true; m_expanded = false; } ServerGroupSettings::ServerGroupSettings(const ServerGroupSettings& settings) : QSharedData() { (*this) = settings; } ServerGroupSettings& Konversation::ServerGroupSettings::operator=(const ServerGroupSettings& settings) { setName(settings.name()); setServerList(settings.serverList()); setIdentityId(settings.identityId()); setChannelList(settings.channelList()); setConnectCommands(settings.connectCommands()); setAutoConnectEnabled(settings.autoConnectEnabled()); setNotificationsEnabled(settings.enableNotifications()); setExpanded(settings.expanded()); m_id = settings.id(); m_sortIndex = settings.sortIndex(); return *this; } ServerGroupSettings::ServerGroupSettings(const QString& name) : QSharedData() { setName(name); m_id = s_availableId; s_availableId++; m_sortIndex = m_id; m_autoConnect = false; m_identityId = 0; m_enableNotifications = true; m_expanded = false; } void ServerGroupSettings::setServerList(const ServerList& list) { m_serverList.clear(); m_serverList = list; } void ServerGroupSettings::removeServer(const ServerSettings& settings) { m_serverList.removeOne(settings); } ServerSettings ServerGroupSettings::serverByIndex(int index) const { ServerList servers = serverList(); if(index < servers.count()) { return servers[index]; } return ServerSettings(); } void ServerGroupSettings::setChannelList(const ChannelList& list) { m_channelList.clear(); m_channelList = list; } ChannelSettings ServerGroupSettings::channelByIndex(int index) const { if(index < m_channelList.count()) { return m_channelList[index]; } return ChannelSettings(); } void ServerGroupSettings::addChannel(const ChannelSettings& channel, const ChannelSettings& before) { if (before.name().isEmpty()) m_channelList.append(channel); else m_channelList.insert(m_channelList.indexOf(before), channel); } void ServerGroupSettings::removeChannel(const ChannelSettings& channel) { m_channelList.removeAll(channel); } + void ServerGroupSettings::removeChannelFromHistory(const ChannelSettings& channel) + { + m_channelHistory.removeAll(channel); + } + IdentityPtr ServerGroupSettings::identity() const { return Preferences::identityById(m_identityId); } void ServerGroupSettings::clearChannelHistory() { m_channelHistory.clear(); } void ServerGroupSettings::appendChannelHistory(const ChannelSettings& channel) { ChannelList::iterator endIt = m_channelHistory.end(); for(ChannelList::iterator it = m_channelHistory.begin(); it != endIt; ++it) { if(channel.name() == (*it).name()) { (*it).setPassword(channel.password()); (*it).setNotificationsEnabled(channel.enableNotifications()); return; } } m_channelHistory.append(channel); } ChannelSettings ServerGroupSettings::channelByNameFromHistory(const QString& channelName) { ChannelList::iterator endIt = m_channelHistory.end(); for(ChannelList::iterator it = m_channelHistory.begin(); it != endIt; ++it) { if(channelName == (*it).name()) { return (*it); } } return ChannelSettings(channelName); } // // ChannelSettings // ChannelSettings::ChannelSettings() { setNotificationsEnabled(true); } ChannelSettings::ChannelSettings(const QString& name) { setName(name); setNotificationsEnabled(true); } ChannelSettings::ChannelSettings(const QString& name, const QString& password) { setName(name); setPassword(password); setNotificationsEnabled(true); } ChannelSettings::ChannelSettings(const QString& name, const QString& password, bool enableNotifications) { setName(name); setPassword(password); setNotificationsEnabled(enableNotifications); } bool ChannelSettings::operator== (const ChannelSettings& channel) const { if (m_name.toLower() == channel.name().toLower()) return true; else return false; } } diff --git a/src/irc/servergroupsettings.h b/src/irc/servergroupsettings.h index 1ac4e6b2..fe5a6e52 100644 --- a/src/irc/servergroupsettings.h +++ b/src/irc/servergroupsettings.h @@ -1,129 +1,130 @@ /* 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. */ /* Copyright (C) 2004, 2007 Peter Simonsson Copyright (C) 2006-2008 Eike Hein */ #ifndef KONVERSATIONSERVERGROUPSETTINGS_H #define KONVERSATIONSERVERGROUPSETTINGS_H #include "serversettings.h" #include "identity.h" #include namespace Konversation { class ChannelSettings { public: ChannelSettings(); explicit ChannelSettings(const QString& name); ChannelSettings(const QString& name, const QString& password); ChannelSettings(const QString& name, const QString& password, bool enableNotifications); void setName(const QString& name) { m_name = name; } QString name() const { return m_name; } void setPassword(const QString& password) { m_password = password; } QString password() const { return m_password; } void setNotificationsEnabled(bool enable) { m_enableNotifications = enable; } bool enableNotifications() const { return m_enableNotifications; } bool operator==(const ChannelSettings& channel) const; private: QString m_name; QString m_password; bool m_enableNotifications; }; class ServerGroupSettings; typedef QExplicitlySharedDataPointer ServerGroupSettingsPtr; typedef QHash ServerGroupHash; typedef QList ServerList; typedef QList ChannelList; class ServerGroupSettings : public QSharedData { public: explicit ServerGroupSettings(); explicit ServerGroupSettings(int id); explicit ServerGroupSettings(const ServerGroupSettings& settings); explicit ServerGroupSettings(const QString& name); ServerGroupSettings& operator=(const ServerGroupSettings& settings); void setName(const QString& name) { m_name = name; } QString name() const { return m_name; } void setServerList(const ServerList& list); void addServer(const ServerSettings& settings) { m_serverList.append(settings); } void removeServer(const ServerSettings& settings); ServerList serverList() const { return m_serverList; } ServerSettings serverByIndex(int index) const; void setIdentityId(int identityId) { m_identityId = identityId; } int identityId() const { return m_identityId; } IdentityPtr identity() const; void setChannelList(const ChannelList& list); void addChannel(const ChannelSettings& channel) { m_channelList.append(channel); } void addChannel(const ChannelSettings& channel, const ChannelSettings& before); void removeChannel(const ChannelSettings& channel); ChannelList channelList() const { return m_channelList; } ChannelSettings channelByIndex(int index) const; void setConnectCommands(const QString& commands) { m_connectCommands = commands; } QString connectCommands() const { return m_connectCommands; } void setAutoConnectEnabled(bool enabled) { m_autoConnect = enabled; } bool autoConnectEnabled() const { return m_autoConnect; } int id() const { return m_id; } void setSortIndex(int sortIndex) { m_sortIndex = sortIndex; } int sortIndex() const { return m_sortIndex; } 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); void setNotificationsEnabled(bool enable) { m_enableNotifications = enable; } bool enableNotifications() const { return m_enableNotifications; } void setExpanded(bool enable) { m_expanded = enable; } bool expanded() const { return m_expanded; } private: static int s_availableId; int m_sortIndex; QString m_name; ServerList m_serverList; int m_identityId; ChannelList m_channelList; ChannelList m_channelHistory; QString m_connectCommands; bool m_autoConnect; QString m_group; int m_id; bool m_enableNotifications; bool m_expanded; }; } #endif