Skip to content

Commit

Permalink
Show a little different icon for bookmarked chats in service discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Il'inykh committed Jun 15, 2017
1 parent c95bc14 commit 933089e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/discodlg.cpp
Expand Up @@ -38,6 +38,7 @@
#include <QEvent>
#include <QList>
#include <QContextMenuEvent>
#include <QPainter>

#include "xmpp_tasks.h"

Expand All @@ -51,10 +52,11 @@
#include "stretchwidget.h"
#include "psioptions.h"
#include "accountlabel.h"
#include "bookmarkmanager.h"

//----------------------------------------------------------------------------

PsiIcon category2icon(const QString &category, const QString &type, int status=STATUS_ONLINE)
PsiIcon category2icon(PsiAccount *acc, const Jid &jid, const QString &category, const QString &type, int status=STATUS_ONLINE)
{
// TODO: update this to http://www.jabber.org/registrar/disco-categories.html#gateway

Expand Down Expand Up @@ -87,8 +89,20 @@ PsiIcon category2icon(const QString &category, const QString &type, int status=S
// smtp
}
else if ( category == "conference" ) {
if (type == "public" || type == "private" || type == "text" || type == "irc")
return IconsetFactory::icon("psi/groupChat");
if (type == "public" || type == "private" || type == "text" || type == "irc") {
PsiIcon icon = IconsetFactory::icon("psi/groupChat");
if (acc->bookmarkManager()->isBookmarked(jid)) {
static QImage img;
if (img.isNull()) {
img = icon.pixmap().toImage();
QPainter p(&img);
PsiIcon bicon = IconsetFactory::icon("psi/bookmark_remove");
p.drawImage(QRect(img.rect().center(),img.rect().bottomRight()), bicon.image());
}
icon.setImpix(Impix(img));
}
return icon;
}
else if (type == "url")
return IconsetFactory::icon("psi/www");
// irc
Expand Down Expand Up @@ -305,7 +319,7 @@ void DiscoListItem::copyItem(const DiscoItem &it)
DiscoItem::Identity id = di.identities().first();

if ( !id.category.isEmpty() ) {
QIcon icon = category2icon(id.category, id.type).icon();
QIcon icon = category2icon(d->pa, di.jid(), id.category, id.type).icon();

if ( !icon.isNull() ) {
setIcon(0, icon);
Expand Down Expand Up @@ -514,7 +528,7 @@ void DiscoListItem::discoInfoFinished()
if ( !di.identities().isEmpty() ) {
DiscoItem::Identity id = di.identities().first();
if ( !id.category.isEmpty() ) {
QIcon icon = category2icon(id.category, id.type, STATUS_ERROR).icon();
QIcon icon = category2icon(d->pa, di.jid(), id.category, id.type, STATUS_ERROR).icon();

if ( !icon.isNull() ) {
setIcon (0, icon);
Expand Down Expand Up @@ -552,8 +566,10 @@ void DiscoListItem::updateInfo(const DiscoItem &item)
class DiscoListView : public QTreeWidget
{
Q_OBJECT

DiscoDlg *dlg;
public:
DiscoListView(QWidget *parent);
DiscoListView(DiscoDlg *parent);

public slots:
void updateItemsVisibility(const QString& filter);
Expand All @@ -566,9 +582,10 @@ public slots:
void resizeEvent(QResizeEvent*);
};

DiscoListView::DiscoListView(QWidget *parent)
DiscoListView::DiscoListView(DiscoDlg *parent)
: QTreeWidget(parent)
{
dlg = parent;
installEventFilter(this);
setHeaderLabels( QStringList() << tr( "Name" ) << tr( "JID" ) << tr( "Node" ) );
// header()->setResizeMode(0, QHeaderView::Stretch);
Expand Down Expand Up @@ -637,7 +654,7 @@ bool DiscoListView::maybeTip(const QPoint &pos)
DiscoItem::Identities::ConstIterator it = item.identities().begin();
for ( ; it != item.identities().end(); ++it) {
text += "<br>";
PsiIcon icon( category2icon((*it).category, (*it).type) );
PsiIcon icon( category2icon(dlg->account(), item.jid(), (*it).category, (*it).type) );
if ( !icon.name().isEmpty() )
text += "<icon name=\"" + icon.name() + "\"> ";
text += (*it).name;
Expand Down Expand Up @@ -1294,4 +1311,9 @@ void DiscoDlg::doDisco(QString host, QString node)
d->doDisco(host, node);
}

PsiAccount *DiscoDlg::account()
{
return d->data.pa;
}

#include "discodlg.moc"
1 change: 1 addition & 0 deletions src/discodlg.h
Expand Up @@ -39,6 +39,7 @@ class DiscoDlg : public QDialog, public Ui::Disco
~DiscoDlg();

void doDisco(QString host = QString::null, QString node = QString::null);
PsiAccount *account();

signals:
void featureActivated(QString feature, Jid jid, QString node);
Expand Down

0 comments on commit 933089e

Please sign in to comment.