Show count of new messages in the toolbar.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5394 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-08-08 10:48:29 +00:00
parent 121d49e5d1
commit 2921cbaf23
7 changed files with 85 additions and 17 deletions

View File

@ -47,7 +47,6 @@
#include "connect/ConnectFriendWizard.h"
#include "forums/CreateForum.h"
#include "gui/common/AvatarDefs.h"
#include "gui/mainpagestack.h"
#include "groups/CreateGroup.h"
#include "im_history/ImHistoryBrowser.h"
#include "MainWindow.h"

View File

@ -372,7 +372,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
for (notifyIt = notify.begin(); notifyIt != notify.end(); ++notifyIt) {
UserNotify *userNotify = notifyIt->first->getUserNotify(this);
if (userNotify) {
userNotify->initialize(notifyIt->second);
userNotify->initialize(ui.toolBar, notifyIt->second);
connect(userNotify, SIGNAL(countChanged()), this, SLOT(updateTrayCombine()));
userNotifyList.push_back(userNotify);
}
@ -660,9 +660,9 @@ void MainWindow::postModDirectories(bool update_local)
}
/** Creates a new action associated with a config page. */
QAction* MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
QAction *MainWindow::createPageAction(const QIcon &icon, const QString &text, QActionGroup *group)
{
QAction *action = new QAction(img, text, group);
QAction *action = new QAction(icon, text, group);
action->setCheckable(true);
action->setFont(FONT);
return action;

View File

@ -208,7 +208,7 @@ private:
BandwidthGraph* _bandwidthGraph;
/** Creates a new action for a Main page. */
QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
QAction* createPageAction(const QIcon &icon, const QString &text, QActionGroup *group);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);

View File

@ -1,18 +1,49 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMenu>
#include <QToolBar>
#include <QToolButton>
#include "UserNotify.h"
UserNotify::UserNotify(QObject *parent) :
QObject(parent)
{
mMainIcon = NULL;
mMainToolButton = NULL;
mMainAction = NULL;
mTrayIcon = NULL;
mNotifyIcon = NULL;
newCount = 0;
}
void UserNotify::initialize(QAction *mainAction)
void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction)
{
mMainIcon = mainAction;
mMainAction = mainAction;
if (mMainAction) {
buttonText = mMainAction->text();
if (mainToolBar) {
mMainToolButton = dynamic_cast<QToolButton*>(mainToolBar->widgetForAction(mMainAction));
}
}
}
void UserNotify::createIcons(QMenu *notifyMenu)
@ -46,8 +77,21 @@ void UserNotify::updateIcon()
{
unsigned int count = getNewCount();
if (mMainIcon) {
mMainIcon->setIcon(getMainIcon(count > 0));
if (mMainAction) {
mMainAction->setIcon(getMainIcon(count > 0));
mMainAction->setText((count > 0) ? QString("%1 (%2)").arg(buttonText).arg(count) : buttonText);
QFont font = mMainAction->font();
font.setBold(count > 0);
mMainAction->setFont(font);
}
if (mMainToolButton) {
mMainToolButton->setStyleSheet((count > 0) ? "QToolButton { color: #E21D3A; }" : "");
QFont font = mMainToolButton->font();
font.setBold(count > 0);
mMainToolButton->setFont(font);
}
if (mTrayIcon) {
@ -73,7 +117,7 @@ void UserNotify::updateIcon()
emit countChanged();
}
count = newCount;
newCount = count;
}
QString UserNotify::getTrayMessage(bool plural)

View File

@ -1,9 +1,32 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef USERNOTIFY_H
#define USERNOTIFY_H
#include <QObject>
#include <QSystemTrayIcon>
class QToolBar;
class QToolButton;
class QAction;
class UserNotify : public QObject
@ -13,7 +36,7 @@ class UserNotify : public QObject
public:
UserNotify(QObject *parent = 0);
void initialize(QAction *mainAction);
void initialize(QToolBar *mainToolBar, QAction *mainAction);
void createIcons(QMenu *notifyMenu);
virtual bool hasSetting(QString &/*name*/) { return false; }
@ -40,10 +63,12 @@ private:
virtual void iconClicked() {}
QAction *mMainIcon;
QToolButton *mMainToolButton;
QAction *mMainAction;
QSystemTrayIcon *mTrayIcon;
QAction *mNotifyIcon;
unsigned int newCount;
QString buttonText;
};
#endif // USERNOTIFY_H

View File

@ -27,7 +27,7 @@
TransferUserNotify::TransferUserNotify(QObject *parent) :
UserNotify(parent)
{
newCount = 0;
newTransferCount = 0;
connect(NotifyQt::getInstance(), SIGNAL(downloadCompleteCountChanged(int)), this, SLOT(downloadCountChanged(int)));
}
@ -80,7 +80,7 @@ QIcon TransferUserNotify::getMainIcon(bool hasNew)
unsigned int TransferUserNotify::getNewCount()
{
return newCount;
return newTransferCount;
}
QString TransferUserNotify::getTrayMessage(bool plural)
@ -100,6 +100,6 @@ void TransferUserNotify::iconClicked()
void TransferUserNotify::downloadCountChanged(int count)
{
newCount = count;
newTransferCount = count;
updateIcon();
}

View File

@ -47,7 +47,7 @@ private:
virtual QString getNotifyMessage(bool plural);
virtual void iconClicked();
int newCount;
unsigned int newTransferCount;
};
#endif // TRANSFERUSERNOTIFY_H