Added blinking of the chat icon for private chat window and chat lobby.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5722 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-10-25 18:06:33 +00:00
parent 179618edbf
commit 7272b7e768
8 changed files with 103 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#include "ui_ChatTabWidget.h" #include "ui_ChatTabWidget.h"
#include "ChatDialog.h" #include "ChatDialog.h"
#include "gui/common/StatusDefs.h" #include "gui/common/StatusDefs.h"
#include "rshare.h"
#define IMAGE_WINDOW ":/images/rstray3.png" #define IMAGE_WINDOW ":/images/rstray3.png"
#define IMAGE_TYPING ":/images/typing.png" #define IMAGE_TYPING ":/images/typing.png"
@ -35,12 +36,20 @@ ChatTabWidget::ChatTabWidget(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
mEmptyIcon = NULL;
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClose(int))); connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClose(int)));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
connect(rApp, SIGNAL(blink(bool)), this, SLOT(blink(bool)));
} }
ChatTabWidget::~ChatTabWidget() ChatTabWidget::~ChatTabWidget()
{ {
if (mEmptyIcon) {
delete(mEmptyIcon);
}
delete ui; delete ui;
} }
@ -91,12 +100,16 @@ void ChatTabWidget::tabInfoChanged(ChatDialog *dialog)
int tab = indexOf(dialog); int tab = indexOf(dialog);
if (tab >= 0) { if (tab >= 0) {
if (dialog->isTyping()) { if (dialog->isTyping()) {
setBlinking(tab, false);
setTabIcon(tab, QIcon(IMAGE_TYPING)); setTabIcon(tab, QIcon(IMAGE_TYPING));
} else if (dialog->hasNewMessages()) { } else if (dialog->hasNewMessages()) {
setTabIcon(tab, QIcon(IMAGE_CHAT)); setTabIcon(tab, QIcon(IMAGE_CHAT));
setBlinking(tab, true);
} else if (dialog->hasPeerStatus()) { } else if (dialog->hasPeerStatus()) {
setBlinking(tab, false);
setTabIcon(tab, QIcon(StatusDefs::imageIM(dialog->getPeerStatus()))); setTabIcon(tab, QIcon(StatusDefs::imageIM(dialog->getPeerStatus())));
} else { } else {
setBlinking(tab, false);
setTabIcon(tab, QIcon()); setTabIcon(tab, QIcon());
} }
} }
@ -143,3 +156,39 @@ void ChatTabWidget::getInfo(bool &isTyping, bool &hasNewMessage, QIcon *icon)
} }
} }
} }
void ChatTabWidget::setBlinking(int tab, bool blink)
{
QIcon icon = tabBar()->tabData(tab).value<QIcon>();
if (blink) {
/* save current icon */
tabBar()->setTabData(tab, tabIcon(tab));
} else {
if (!icon.isNull()) {
/* reset icon */
setTabIcon(tab, icon);
/* remove icon */
tabBar()->setTabData(tab, QVariant());
}
}
}
void ChatTabWidget::blink(bool on)
{
int tabCount = tabBar()->count();
for (int tab = 0; tab < tabCount; ++tab) {
QIcon icon = tabBar()->tabData(tab).value<QIcon>();
if (!icon.isNull()) {
if (mEmptyIcon == NULL) {
/* create empty icon */
QPixmap pixmap(16, 16);
pixmap.fill(Qt::transparent);
mEmptyIcon = new QIcon(pixmap);
}
tabBar()->setTabIcon(tab, on ? icon : *mEmptyIcon);
}
}
}

View File

@ -43,6 +43,7 @@ public:
void removeDialog(ChatDialog *dialog); void removeDialog(ChatDialog *dialog);
void getInfo(bool &isTyping, bool &hasNewMessage, QIcon *icon); void getInfo(bool &isTyping, bool &hasNewMessage, QIcon *icon);
void setBlinking(int tab, bool blink);
signals: signals:
void tabChanged(ChatDialog *dialog); void tabChanged(ChatDialog *dialog);
@ -54,8 +55,11 @@ private slots:
void tabChanged(int tab); void tabChanged(int tab);
void tabInfoChanged(ChatDialog *dialog); void tabInfoChanged(ChatDialog *dialog);
void dialogClose(ChatDialog *dialog); void dialogClose(ChatDialog *dialog);
void blink(bool on);
private: private:
QIcon *mEmptyIcon;
Ui::ChatTabWidget *ui; Ui::ChatTabWidget *ui;
}; };

View File

@ -30,6 +30,7 @@
#include "gui/common/StatusDefs.h" #include "gui/common/StatusDefs.h"
#include "gui/style/RSStyle.h" #include "gui/style/RSStyle.h"
#include "util/misc.h" #include "util/misc.h"
#include "rshare.h"
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include <retroshare/rsnotify.h> #include <retroshare/rsnotify.h>
@ -70,6 +71,7 @@ PopupChatWindow::PopupChatWindow(bool tabbed, QWidget *parent, Qt::WFlags flags)
tabbedWindow = tabbed; tabbedWindow = tabbed;
firstShow = true; firstShow = true;
chatDialog = NULL; chatDialog = NULL;
mEmptyIcon = NULL;
ui.tabWidget->setVisible(tabbedWindow); ui.tabWidget->setVisible(tabbedWindow);
@ -92,6 +94,8 @@ PopupChatWindow::PopupChatWindow(bool tabbed, QWidget *parent, Qt::WFlags flags)
connect(ui.tabWidget, SIGNAL(tabChanged(ChatDialog*)), this, SLOT(tabChanged(ChatDialog*))); connect(ui.tabWidget, SIGNAL(tabChanged(ChatDialog*)), this, SLOT(tabChanged(ChatDialog*)));
connect(ui.tabWidget, SIGNAL(tabClosed(ChatDialog*)), this, SLOT(tabClosed(ChatDialog*))); connect(ui.tabWidget, SIGNAL(tabClosed(ChatDialog*)), this, SLOT(tabClosed(ChatDialog*)));
connect(rApp, SIGNAL(blink(bool)), this, SLOT(blink(bool)));
if (tabbedWindow) { if (tabbedWindow) {
/* signal toggled is called */ /* signal toggled is called */
ui.actionSetOnTop->setChecked(Settings->valueFromGroup("ChatWindow", "OnTop", false).toBool()); ui.actionSetOnTop->setChecked(Settings->valueFromGroup("ChatWindow", "OnTop", false).toBool());
@ -105,6 +109,10 @@ PopupChatWindow::~PopupChatWindow()
{ {
saveSettings(); saveSettings();
if (mEmptyIcon) {
delete(mEmptyIcon);
}
if (this == instance) { if (this == instance) {
instance = NULL; instance = NULL;
} }
@ -263,10 +271,13 @@ void PopupChatWindow::calculateTitle(ChatDialog *dialog)
QIcon icon; QIcon icon;
if (isTyping) { if (isTyping) {
mBlinkIcon = QIcon();
icon = QIcon(IMAGE_TYPING); icon = QIcon(IMAGE_TYPING);
} else if (hasNewMessages) { } else if (hasNewMessages) {
icon = QIcon(IMAGE_CHAT); icon = QIcon(IMAGE_CHAT);
mBlinkIcon = icon;
} else { } else {
mBlinkIcon = QIcon();
if (cd && cd->hasPeerStatus()) { if (cd && cd->hasPeerStatus()) {
icon = QIcon(StatusDefs::imageIM(cd->getPeerStatus())); icon = QIcon(StatusDefs::imageIM(cd->getPeerStatus()));
} else { } else {
@ -405,3 +416,16 @@ void PopupChatWindow::calculateStyle(ChatDialog *dialog)
ui.chatstatusbar->setStyleSheet(statusSheet); ui.chatstatusbar->setStyleSheet(statusSheet);
ui.chatcentralwidget->setStyleSheet(widgetSheet); ui.chatcentralwidget->setStyleSheet(widgetSheet);
} }
void PopupChatWindow::blink(bool on)
{
if (!mBlinkIcon.isNull()) {
if (mEmptyIcon == NULL) {
/* create empty icon */
QPixmap pixmap(16, 16);
pixmap.fill(Qt::transparent);
mEmptyIcon = new QIcon(pixmap);
}
setWindowIcon(on ? mBlinkIcon : *mEmptyIcon);
}
}

View File

@ -63,12 +63,15 @@ private slots:
void undockTab(); void undockTab();
void setStyle(); void setStyle();
void setOnTop(); void setOnTop();
void blink(bool on);
private: private:
bool tabbedWindow; bool tabbedWindow;
bool firstShow; bool firstShow;
std::string peerId; std::string peerId;
ChatDialog *chatDialog; ChatDialog *chatDialog;
QIcon mBlinkIcon;
QIcon *mEmptyIcon;
ChatDialog *getCurrentDialog(); ChatDialog *getCurrentDialog();
void saveSettings(); void saveSettings();

View File

@ -22,9 +22,9 @@
#include <QMenu> #include <QMenu>
#include <QToolBar> #include <QToolBar>
#include <QToolButton> #include <QToolButton>
#include <QTimer>
#include "UserNotify.h" #include "UserNotify.h"
#include "rshare.h"
UserNotify::UserNotify(QObject *parent) : UserNotify::UserNotify(QObject *parent) :
QObject(parent) QObject(parent)
@ -36,10 +36,7 @@ UserNotify::UserNotify(QObject *parent) :
mNewCount = 0; mNewCount = 0;
mLastBlinking = false; mLastBlinking = false;
mTimer = new QTimer(this); connect(rApp, SIGNAL(blink(bool)), this, SLOT(blink(bool)));
mTimer->setInterval(500);
connect(mTimer, SIGNAL(timeout()), this, SLOT(timer()));
} }
void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction) void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction)
@ -109,11 +106,7 @@ void UserNotify::updateIcon()
if (count) { if (count) {
mTrayIcon->setToolTip("RetroShare\n" + getTrayMessage(count > 1).arg(count)); mTrayIcon->setToolTip("RetroShare\n" + getTrayMessage(count > 1).arg(count));
mTrayIcon->show(); mTrayIcon->show();
if (!mTimer->isActive()) {
mTimer->start();
}
} else { } else {
mTimer->stop();
mTrayIcon->hide(); mTrayIcon->hide();
} }
} }
@ -152,18 +145,14 @@ void UserNotify::trayIconClicked(QSystemTrayIcon::ActivationReason e)
} }
} }
void UserNotify::timer() void UserNotify::blink(bool on)
{ {
bool blinking = isBlinking(); bool blinking = isBlinking();
if (mTrayIcon) { if (mTrayIcon) {
if (blinking) { if (blinking) {
/* blink icon */ /* blink icon */
if (mTrayIcon->icon().isNull()) { mTrayIcon->setIcon(on ? getIcon() : QIcon());
mTrayIcon->setIcon(getIcon());
} else {
mTrayIcon->setIcon(QIcon());
}
} else { } else {
if (mLastBlinking) { if (mLastBlinking) {
/* reset icon */ /* reset icon */

View File

@ -28,7 +28,6 @@
class QToolBar; class QToolBar;
class QToolButton; class QToolButton;
class QAction; class QAction;
class QTimer;
class UserNotify : public QObject class UserNotify : public QObject
{ {
@ -53,7 +52,7 @@ public slots:
private slots: private slots:
void trayIconClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger); void trayIconClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void timer(); void blink(bool on);
private: private:
virtual QIcon getIcon() { return QIcon(); } virtual QIcon getIcon() { return QIcon(); }
@ -72,7 +71,6 @@ private:
QAction *mNotifyIcon; QAction *mNotifyIcon;
unsigned int mNewCount; unsigned int mNewCount;
QString mButtonText; QString mButtonText;
QTimer *mTimer;
bool mLastBlinking; bool mLastBlinking;
}; };

View File

@ -100,6 +100,11 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir)
#endif #endif
mBlink = true;
QTimer *timer = new QTimer(this);
timer->setInterval(500);
connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer()));
timer->start();
/* Read in all our command-line arguments. */ /* Read in all our command-line arguments. */
parseArguments(args); parseArguments(args);
@ -527,3 +532,9 @@ Rshare::createShortcut(const QKeySequence &key, QWidget *sender,
QShortcut *s = new QShortcut(key, sender); QShortcut *s = new QShortcut(key, sender);
connect(s, SIGNAL(activated()), receiver, slot); connect(s, SIGNAL(activated()), receiver, slot);
} }
void Rshare::blinkTimer()
{
mBlink = !mBlink;
emit blink(mBlink);
}

View File

@ -130,6 +130,8 @@ signals:
void running(); void running();
/** Signals that the application needs to shutdown now. */ /** Signals that the application needs to shutdown now. */
void shutdown(); void shutdown();
/** Global blink timer */
void blink(bool on);
protected: protected:
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
@ -142,7 +144,7 @@ private slots:
* will emit the running() signal to indicate that the application's event * will emit the running() signal to indicate that the application's event
* loop is running. */ * loop is running. */
void onEventLoopStarted(); void onEventLoopStarted();
void blinkTimer();
private: private:
/** Catches debugging messages from Qt and sends them to /** Catches debugging messages from Qt and sends them to
@ -162,7 +164,7 @@ private:
static bool useConfigDir; static bool useConfigDir;
static QString configDir; static QString configDir;
bool mBlink;
}; };
#endif #endif