From ac654fdeeece68d64561920479f064ad3c237e26 Mon Sep 17 00:00:00 2001 From: Bas Pape Date: Mon, 26 Aug 2013 23:01:25 +0200 Subject: [PATCH 1/1] Indicate whether a key is set for the buffer. This adds a lock icon on the right of the input widget when a key is set for the current buffer. Encryption was isolated within CoreIrcUser and CoreIrcChannel, so a new property on IrcUser and IrcChannel is necessary to sync the current status. --- src/client/networkmodel.cpp | 3 +++ src/client/networkmodel.h | 1 + src/common/ircchannel.cpp | 8 ++++++++ src/common/ircchannel.h | 5 +++++ src/common/ircuser.cpp | 9 +++++++++ src/common/ircuser.h | 5 +++++ src/core/coreircchannel.cpp | 2 ++ src/core/coreircuser.cpp | 7 ------- src/core/coreircuser.h | 1 - src/qtui/inputwidget.cpp | 19 ++++++++++++++++++- src/qtui/ui/inputwidget.ui | 7 +++++++ 11 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 1a2da5e8..e81f6c03 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -522,6 +522,7 @@ void QueryBufferItem::setIrcUser(IrcUser *ircUser) if (ircUser) { connect(ircUser, SIGNAL(quited()), this, SLOT(removeIrcUser())); connect(ircUser, SIGNAL(awaySet(bool)), this, SIGNAL(dataChanged())); + connect(ircUser, SIGNAL(encryptedSet(bool)), this, SLOT(setEncrypted(bool))); } _ircUser = ircUser; @@ -600,6 +601,8 @@ void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel) connect(ircChannel, SIGNAL(topicSet(QString)), this, SLOT(setTopic(QString))); + connect(ircChannel, SIGNAL(encryptedSet(bool)), + this, SLOT(setEncrypted(bool))); connect(ircChannel, SIGNAL(ircUsersJoined(QList )), this, SLOT(join(QList ))); connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)), diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index f0d4c02a..8a5819ef 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -125,6 +125,7 @@ public : public slots: virtual inline void setTopic(const QString &) { emit dataChanged(1); } + virtual inline void setEncrypted(bool) { emit dataChanged(); } private: BufferInfo _bufferInfo; diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 3fc34610..8b246c29 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -36,6 +36,7 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network) _initialized(false), _name(channelname), _topic(QString()), + _encrypted(false), _network(network), _codecForEncoding(0), _codecForDecoding(0) @@ -151,6 +152,13 @@ void IrcChannel::setPassword(const QString &password) SYNC(ARG(password)) } +void IrcChannel::setEncrypted(bool encrypted) +{ + _encrypted = encrypted; + SYNC(ARG(encrypted)) + emit encryptedSet(encrypted); +} + void IrcChannel::joinIrcUsers(const QList &users, const QStringList &modes) { diff --git a/src/common/ircchannel.h b/src/common/ircchannel.h index c0ee0705..b27ea90e 100644 --- a/src/common/ircchannel.h +++ b/src/common/ircchannel.h @@ -40,6 +40,7 @@ class IrcChannel : public SyncableObject Q_PROPERTY(QString name READ name STORED false) Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false) Q_PROPERTY(QString password READ password WRITE setPassword STORED false) + Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted STORED false) public : IrcChannel(const QString &channelname, Network *network); @@ -51,6 +52,7 @@ public : inline QString name() const { return _name; } inline QString topic() const { return _topic; } inline QString password() const { return _password; } + inline bool encrypted() const { return _encrypted; } inline Network *network() const { return _network; } inline QList ircUsers() const { return _userModes.keys(); } @@ -76,6 +78,7 @@ public : public slots: void setTopic(const QString &topic); void setPassword(const QString &password); + void setEncrypted(bool encrypted); void joinIrcUsers(const QList &users, const QStringList &modes); void joinIrcUsers(const QStringList &nicks, const QStringList &modes); @@ -106,6 +109,7 @@ public slots: signals: void topicSet(const QString &topic); // needed by NetworkModel + void encryptedSet(bool encrypted); // void passwordSet(const QString &password); // void userModesSet(QString nick, QString modes); // void userModeAdded(QString nick, QString mode); @@ -132,6 +136,7 @@ private: QString _name; QString _topic; QString _password; + bool _encrypted; QHash _userModes; diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index b9f359e1..ddae4ee2 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -42,6 +42,7 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net _ircOperator(), _lastAwayMessage(0), _whoisServiceReply(), + _encrypted(false), _network(network), _codecForEncoding(0), _codecForDecoding(0) @@ -248,6 +249,14 @@ void IrcUser::setSuserHost(const QString &suserHost) } +void IrcUser::setEncrypted(bool encrypted) +{ + _encrypted = encrypted; + emit encryptedSet(encrypted); + SYNC(ARG(encrypted)) +} + + void IrcUser::updateObjectName() { renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); diff --git a/src/common/ircuser.h b/src/common/ircuser.h index 3ff272dd..fe21dfa9 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -52,6 +52,7 @@ class IrcUser : public SyncableObject Q_PROPERTY(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage STORED false) Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply STORED false) Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost STORED false) + Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted STORED false) Q_PROPERTY(QStringList channels READ channels STORED false) Q_PROPERTY(QString userModes READ userModes WRITE setUserModes) @@ -74,6 +75,7 @@ public : inline int lastAwayMessage() const { return _lastAwayMessage; } inline QString whoisServiceReply() const { return _whoisServiceReply; } inline QString suserHost() const { return _suserHost; } + inline bool encrypted() const { return _encrypted; } inline Network *network() const { return _network; } inline QString userModes() const { return _userModes; } @@ -111,6 +113,7 @@ public slots: void setLastAwayMessage(const int &lastAwayMessage); void setWhoisServiceReply(const QString &whoisServiceReply); void setSuserHost(const QString &suserHost); + void setEncrypted(bool encrypted); void updateHostmask(const QString &mask); void setUserModes(const QString &modes); @@ -138,6 +141,7 @@ signals: // void lastAwayMessageSet(int lastAwayMessage); // void whoisServiceReplySet(QString whoisServiceReply); // void suserHostSet(QString suserHost); + void encryptedSet(bool encrypted); void userModesSet(QString modes); void userModesAdded(QString modes); @@ -183,6 +187,7 @@ private: int _lastAwayMessage; QString _whoisServiceReply; QString _suserHost; + bool _encrypted; // QSet _channels; QSet _channels; diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index 99d18815..7ec82b93 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -52,6 +52,8 @@ Cipher *CoreIrcChannel::cipher() const void CoreIrcChannel::setEncrypted(bool e) { + IrcChannel::setEncrypted(e); + if (!Cipher::neededFeaturesAvailable()) return; diff --git a/src/core/coreircuser.cpp b/src/core/coreircuser.cpp index 79f5d38a..f89e9aa6 100644 --- a/src/core/coreircuser.cpp +++ b/src/core/coreircuser.cpp @@ -46,11 +46,4 @@ Cipher *CoreIrcUser::cipher() const } -void CoreIrcUser::setEncrypted(bool e) -{ - Q_UNUSED(e); - // TODO -} - - #endif diff --git a/src/core/coreircuser.h b/src/core/coreircuser.h index cc5a9f8a..af0f6348 100644 --- a/src/core/coreircuser.h +++ b/src/core/coreircuser.h @@ -40,7 +40,6 @@ public: #ifdef HAVE_QCA2 Cipher *cipher() const; - void setEncrypted(bool); #endif #ifdef HAVE_QCA2 diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index c246f2e7..86052a00 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -65,6 +65,7 @@ InputWidget::InputWidget(QWidget *parent) ui.underlineButton->setIcon(SmallIcon("format-text-underline")); ui.textcolorButton->setIcon(SmallIcon("format-text-color")); ui.highlightcolorButton->setIcon(SmallIcon("format-fill-color")); + ui.encryptionIconLabel->hide(); _colorMenu = new QMenu(); _colorFillMenu = new QMenu(); @@ -289,8 +290,24 @@ void InputWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot QItemSelectionRange changedArea(topLeft, bottomRight); if (changedArea.contains(selectionModel()->currentIndex())) { updateEnabledState(); + + bool encrypted = false; + + IrcChannel *chan = qobject_cast(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value()); + if (chan) + encrypted = chan->encrypted(); + + IrcUser *user = qobject_cast(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcUserRole).value()); + if (user) + encrypted = user->encrypted(); + + if (encrypted) + ui.encryptionIconLabel->show(); + else + ui.encryptionIconLabel->hide(); } -}; +} + void InputWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { diff --git a/src/qtui/ui/inputwidget.ui b/src/qtui/ui/inputwidget.ui index 9ce97ae0..edb4f843 100644 --- a/src/qtui/ui/inputwidget.ui +++ b/src/qtui/ui/inputwidget.ui @@ -292,6 +292,13 @@ + + + + <img src=":/icons/oxygen/16x16/actions/document-encrypt.png"> + + + -- 2.20.1