X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fbufferviewconfig.cpp;h=3bd71f79e8472509f117946749c756f269eeb55c;hp=d54097d4ee597f8ff6ae2f6617d213c8104d7405;hb=1f21c1f9613031ae263eeed0c4883bfcd5488343;hpb=288bdd13039b6f94b50155982b74b67b0b79a9f9 diff --git a/src/common/bufferviewconfig.cpp b/src/common/bufferviewconfig.cpp index d54097d4..3bd71f79 100644 --- a/src/common/bufferviewconfig.cpp +++ b/src/common/bufferviewconfig.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,139 +15,353 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "bufferviewconfig.h" -#include "bufferinfo.h" +BufferViewConfig::BufferViewConfig(int bufferViewId, QObject* parent) + : SyncableObject(parent) + , _bufferViewId(bufferViewId) +{ + setObjectName(QString::number(bufferViewId)); +} + +BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap& properties, QObject* parent) + : SyncableObject(parent) + , _bufferViewId(bufferViewId) +{ + fromVariantMap(properties); + setObjectName(QString::number(bufferViewId)); +} + +int BufferViewConfig::bufferViewId() const +{ + return _bufferViewId; +} + +QString BufferViewConfig::bufferViewName() const +{ + return _bufferViewName; +} + +NetworkId BufferViewConfig::networkId() const +{ + return _networkId; +} + +bool BufferViewConfig::addNewBuffersAutomatically() const +{ + return _addNewBuffersAutomatically; +} + +bool BufferViewConfig::sortAlphabetically() const +{ + return _sortAlphabetically; +} + +bool BufferViewConfig::disableDecoration() const +{ + return _disableDecoration; +} + +int BufferViewConfig::allowedBufferTypes() const +{ + return _allowedBufferTypes; +} + +int BufferViewConfig::minimumActivity() const +{ + return _minimumActivity; +} + +bool BufferViewConfig::hideInactiveBuffers() const +{ + return _hideInactiveBuffers; +} + +bool BufferViewConfig::hideInactiveNetworks() const +{ + return _hideInactiveNetworks; +} + +bool BufferViewConfig::showSearch() const +{ + return _showSearch; +} + +QList BufferViewConfig::bufferList() const +{ + return _buffers; +} + +QSet BufferViewConfig::removedBuffers() const +{ + return _removedBuffers; +} + +QSet BufferViewConfig::temporarilyRemovedBuffers() const +{ + return _temporarilyRemovedBuffers; +} + +QVariantList BufferViewConfig::initBufferList() const +{ + QVariantList buffers; + + foreach (BufferId bufferId, _buffers) { + buffers << QVariant::fromValue(bufferId); + } + + return buffers; +} + +void BufferViewConfig::initSetBufferList(const QVariantList& buffers) +{ + _buffers.clear(); + + foreach (QVariant buffer, buffers) { + _buffers << buffer.value(); + } -BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent) - : SyncableObject(parent), - _bufferViewId(bufferViewId), - _addNewBuffersAutomatically(true), - _sortAlphabetically(true), - _hideInactiveBuffers(false), - _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer), - _minimumActivity(0) + emit configChanged(); // used to track changes in the settingspage +} + +QVariantList BufferViewConfig::initRemovedBuffers() const { - setObjectName(QString::number(bufferViewId)); + QVariantList removedBuffers; + + foreach (BufferId bufferId, _removedBuffers) { + removedBuffers << QVariant::fromValue(bufferId); + } + + return removedBuffers; } -BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent) - : SyncableObject(parent), - _bufferViewId(bufferViewId) +void BufferViewConfig::initSetRemovedBuffers(const QVariantList& buffers) { - fromVariantMap(properties); - setObjectName(QString::number(bufferViewId)); + _removedBuffers.clear(); + + foreach (QVariant buffer, buffers) { + _removedBuffers << buffer.value(); + } } -void BufferViewConfig::setBufferViewName(const QString &bufferViewName) { - if(_bufferViewName == bufferViewName) - return; +QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const +{ + QVariantList temporarilyRemovedBuffers; + + foreach (BufferId bufferId, _temporarilyRemovedBuffers) { + temporarilyRemovedBuffers << QVariant::fromValue(bufferId); + } - _bufferViewName = bufferViewName; - emit bufferViewNameSet(bufferViewName); + return temporarilyRemovedBuffers; } -void BufferViewConfig::setNetworkId(const NetworkId &networkId) { - if(_networkId == networkId) - return; +void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList& buffers) +{ + _temporarilyRemovedBuffers.clear(); - _networkId = networkId; - emit networkIdSet(networkId); + foreach (QVariant buffer, buffers) { + _temporarilyRemovedBuffers << buffer.value(); + } } -void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) { - if(_addNewBuffersAutomatically == addNewBuffersAutomatically) - return; +void BufferViewConfig::setBufferViewName(const QString& bufferViewName) +{ + if (_bufferViewName == bufferViewName) + return; - _addNewBuffersAutomatically = addNewBuffersAutomatically; - emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically); + _bufferViewName = bufferViewName; + SYNC(ARG(bufferViewName)) + emit bufferViewNameSet(bufferViewName); } -void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) { - if(_sortAlphabetically == sortAlphabetically) - return; +void BufferViewConfig::setNetworkId(const NetworkId& networkId) +{ + if (_networkId == networkId) + return; - _sortAlphabetically = sortAlphabetically; - emit sortAlphabeticallySet(sortAlphabetically); + _networkId = networkId; + SYNC(ARG(networkId)) + emit networkIdSet(networkId); + emit configChanged(); } -void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) { - if(_allowedBufferTypes == bufferTypes) - return; +void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) +{ + if (_addNewBuffersAutomatically == addNewBuffersAutomatically) + return; - _allowedBufferTypes = bufferTypes; - emit allowedBufferTypesSet(bufferTypes); + _addNewBuffersAutomatically = addNewBuffersAutomatically; + SYNC(ARG(addNewBuffersAutomatically)) + emit configChanged(); } -void BufferViewConfig::setMinimumActivity(int activity) { - if(_minimumActivity == activity) - return; +void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) +{ + if (_sortAlphabetically == sortAlphabetically) + return; - _minimumActivity = activity; - emit minimumActivitySet(activity); + _sortAlphabetically = sortAlphabetically; + SYNC(ARG(sortAlphabetically)) + emit configChanged(); } -void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) { - if(_hideInactiveBuffers == hideInactiveBuffers) - return; +void BufferViewConfig::setDisableDecoration(bool disableDecoration) +{ + if (_disableDecoration == disableDecoration) + return; - _hideInactiveBuffers = hideInactiveBuffers; - emit hideInactiveBuffersSet(hideInactiveBuffers); + _disableDecoration = disableDecoration; + SYNC(ARG(disableDecoration)) } -QVariantList BufferViewConfig::initBufferList() const { - QVariantList buffers; +void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) +{ + if (_allowedBufferTypes == bufferTypes) + return; + + _allowedBufferTypes = bufferTypes; + SYNC(ARG(bufferTypes)) + emit configChanged(); +} - foreach(BufferId bufferId, _buffers) { - buffers << qVariantFromValue(bufferId); - } +void BufferViewConfig::setMinimumActivity(int activity) +{ + if (_minimumActivity == activity) + return; - return buffers; + _minimumActivity = activity; + SYNC(ARG(activity)) + emit configChanged(); } -void BufferViewConfig::initSetBufferList(const QVariantList &buffers) { - _buffers.clear(); +void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) +{ + if (_hideInactiveBuffers == hideInactiveBuffers) + return; - foreach(QVariant buffer, buffers) { - _buffers << buffer.value(); - } + _hideInactiveBuffers = hideInactiveBuffers; + SYNC(ARG(hideInactiveBuffers)) + emit configChanged(); +} + +void BufferViewConfig::setHideInactiveNetworks(bool hideInactiveNetworks) +{ + if (_hideInactiveNetworks == hideInactiveNetworks) + return; - emit bufferListSet(); + _hideInactiveNetworks = hideInactiveNetworks; + SYNC(ARG(hideInactiveNetworks)) + emit configChanged(); } -void BufferViewConfig::initSetBufferList(const QList &buffers) { - _buffers.clear(); +void BufferViewConfig::setShowSearch(bool showSearch) +{ + if (_showSearch == showSearch) { + return; + } - foreach(BufferId bufferId, buffers) { - _buffers << bufferId; - } + _showSearch = showSearch; + SYNC(ARG(showSearch)) + emit configChanged(); +} - emit bufferListSet(); +void BufferViewConfig::setBufferList(const QList& buffers) +{ + _buffers = buffers; + emit configChanged(); } -void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) { - if(_buffers.contains(bufferId)) - return; - - _buffers.insert(pos, bufferId); - emit bufferAdded(bufferId, pos); +void BufferViewConfig::addBuffer(const BufferId& bufferId, int pos) +{ + if (_buffers.contains(bufferId)) + return; + + if (pos < 0) + pos = 0; + if (pos > _buffers.count()) + pos = _buffers.count(); + + if (_removedBuffers.contains(bufferId)) + _removedBuffers.remove(bufferId); + + if (_temporarilyRemovedBuffers.contains(bufferId)) + _temporarilyRemovedBuffers.remove(bufferId); + + _buffers.insert(pos, bufferId); + SYNC(ARG(bufferId), ARG(pos)) + emit bufferAdded(bufferId, pos); + emit configChanged(); +} + +void BufferViewConfig::moveBuffer(const BufferId& bufferId, int pos) +{ + if (!_buffers.contains(bufferId)) + return; + + if (pos < 0) + pos = 0; + if (pos >= _buffers.count()) + pos = _buffers.count() - 1; + + _buffers.move(_buffers.indexOf(bufferId), pos); + SYNC(ARG(bufferId), ARG(pos)) + emit bufferMoved(bufferId, pos); + emit configChanged(); +} + +void BufferViewConfig::removeBuffer(const BufferId& bufferId) +{ + if (_buffers.contains(bufferId)) + _buffers.removeAt(_buffers.indexOf(bufferId)); + + if (_removedBuffers.contains(bufferId)) + _removedBuffers.remove(bufferId); + + _temporarilyRemovedBuffers << bufferId; + SYNC(ARG(bufferId)) + emit bufferRemoved(bufferId); + emit configChanged(); } -void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) { - if(!_buffers.contains(bufferId)) - return; +void BufferViewConfig::removeBufferPermanently(const BufferId& bufferId) +{ + if (_buffers.contains(bufferId)) + _buffers.removeAt(_buffers.indexOf(bufferId)); + + if (_temporarilyRemovedBuffers.contains(bufferId)) + _temporarilyRemovedBuffers.remove(bufferId); + + _removedBuffers << bufferId; - _buffers.move(_buffers.indexOf(bufferId), pos); - emit bufferMoved(bufferId, pos); + SYNC(ARG(bufferId)) + emit bufferPermanentlyRemoved(bufferId); + emit configChanged(); } -void BufferViewConfig::removeBuffer(const BufferId &bufferId) { - if(!_buffers.contains(bufferId)) - return; - - _buffers.removeAt(_buffers.indexOf(bufferId)); - emit bufferRemoved(bufferId); +void BufferViewConfig::requestSetBufferViewName(const QString& bufferViewName) +{ + REQUEST(ARG(bufferViewName)) +} + +void BufferViewConfig::requestAddBuffer(const BufferId& bufferId, int pos) +{ + REQUEST(ARG(bufferId), ARG(pos)) +} + +void BufferViewConfig::requestMoveBuffer(const BufferId& bufferId, int pos) +{ + REQUEST(ARG(bufferId), ARG(pos)) +} + +void BufferViewConfig::requestRemoveBuffer(const BufferId& bufferId) +{ + REQUEST(ARG(bufferId)) +} + +void BufferViewConfig::requestRemoveBufferPermanently(const BufferId& bufferId) +{ + REQUEST(ARG(bufferId)) }