Indicate whether a key is set for the buffer.
authorBas Pape <baspape@gmail.com>
Mon, 26 Aug 2013 21:01:25 +0000 (23:01 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 10 Oct 2013 18:08:18 +0000 (20:08 +0200)
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
src/client/networkmodel.h
src/common/ircchannel.cpp
src/common/ircchannel.h
src/common/ircuser.cpp
src/common/ircuser.h
src/core/coreircchannel.cpp
src/core/coreircuser.cpp
src/core/coreircuser.h
src/qtui/inputwidget.cpp
src/qtui/ui/inputwidget.ui

index 1a2da5e..e81f6c0 100644 (file)
@@ -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<IrcUser *> )),
         this, SLOT(join(QList<IrcUser *> )));
     connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
index f0d4c02..8a5819e 100644 (file)
@@ -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;
index 3fc3461..8b246c2 100644 (file)
@@ -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<IrcUser *> &users, const QStringList &modes)
 {
index c0ee070..b27ea90 100644 (file)
@@ -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<IrcUser *> 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<IrcUser *> &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<IrcUser *, QString> _userModes;
 
index b9f359e..ddae4ee 100644 (file)
@@ -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);
index 3ff272d..fe21dfa 100644 (file)
@@ -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<QString> _channels;
     QSet<IrcChannel *> _channels;
index 99d1881..7ec82b9 100644 (file)
@@ -52,6 +52,8 @@ Cipher *CoreIrcChannel::cipher() const
 
 void CoreIrcChannel::setEncrypted(bool e)
 {
+    IrcChannel::setEncrypted(e);
+
     if (!Cipher::neededFeaturesAvailable())
         return;
 
index 79f5d38..f89e9aa 100644 (file)
@@ -46,11 +46,4 @@ Cipher *CoreIrcUser::cipher() const
 }
 
 
-void CoreIrcUser::setEncrypted(bool e)
-{
-    Q_UNUSED(e);
-    // TODO
-}
-
-
 #endif
index cc5a9f8..af0f634 100644 (file)
@@ -40,7 +40,6 @@ public:
 
 #ifdef HAVE_QCA2
     Cipher *cipher() const;
-    void setEncrypted(bool);
 #endif
 
 #ifdef HAVE_QCA2
index c246f2e..86052a0 100644 (file)
@@ -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<IrcChannel *>(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value<QObject *>());
+        if (chan)
+            encrypted = chan->encrypted();
+
+        IrcUser *user = qobject_cast<IrcUser *>(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcUserRole).value<QObject *>());
+        if (user)
+            encrypted = user->encrypted();
+
+        if (encrypted)
+            ui.encryptionIconLabel->show();
+        else
+            ui.encryptionIconLabel->hide();
     }
-};
+}
+
 
 void InputWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
 {
index 9ce97ae..edb4f84 100644 (file)
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QLabel" name="encryptionIconLabel">
+      <property name="text">
+       <string>&lt;img src=&quot;:/icons/oxygen/16x16/actions/document-encrypt.png&quot;&gt;</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <customwidgets>