Merge pull request #2335 from PhenomRetroShare/Fix_UserNotifyToolTip

Fix UserNotify ToolTip
This commit is contained in:
defnax 2021-02-18 21:15:20 +01:00 committed by GitHub
commit 083b6ea7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 121 additions and 80 deletions

View File

@ -66,12 +66,12 @@ unsigned int TransferUserNotify::getNewCount()
QString TransferUserNotify::getTrayMessage(bool plural) QString TransferUserNotify::getTrayMessage(bool plural)
{ {
return plural ? tr("You have %1 completed downloads") : tr("You have %1 completed download"); return plural ? tr("You have %1 completed transfers") : tr("You have %1 completed transfer");
} }
QString TransferUserNotify::getNotifyMessage(bool plural) QString TransferUserNotify::getNotifyMessage(bool plural)
{ {
return plural ? tr("%1 completed downloads") : tr("%1 completed download"); return plural ? tr("%1 completed transfers") : tr("%1 completed transfer");
} }
void TransferUserNotify::iconClicked() void TransferUserNotify::iconClicked()

View File

@ -30,16 +30,17 @@ class TransferUserNotify : public UserNotify
public: public:
TransferUserNotify(QObject *parent = 0); TransferUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("completed transfer(s)"); }
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual unsigned int getNewCount(); virtual unsigned int getNewCount() override;
virtual QString getTrayMessage(bool plural);
virtual QString getNotifyMessage(bool plural); virtual QString getTrayMessage(bool plural) override;
virtual void iconClicked(); virtual QString getNotifyMessage(bool plural) override;
virtual void iconClicked() override;
unsigned int newTransferCount; unsigned int newTransferCount;
}; };

View File

@ -491,7 +491,7 @@ void MainWindow::initStackedPage()
for (notifyIt = notify.begin(); notifyIt != notify.end(); ++notifyIt) { for (notifyIt = notify.begin(); notifyIt != notify.end(); ++notifyIt) {
UserNotify *userNotify = notifyIt->first->getUserNotify(); UserNotify *userNotify = notifyIt->first->getUserNotify();
if (userNotify) { if (userNotify) {
userNotify->initialize(ui->toolBarPage, notifyIt->second.first, notifyIt->second.second,userNotify->textInfo()); userNotify->initialize(ui->toolBarPage, notifyIt->second.first, notifyIt->second.second);
connect(userNotify, SIGNAL(countChanged()), this, SLOT(updateTrayCombine())); connect(userNotify, SIGNAL(countChanged()), this, SLOT(updateTrayCombine()));
userNotifyList.push_back(userNotify); userNotifyList.push_back(userNotify);
} }

View File

@ -46,6 +46,16 @@ QIcon PostedUserNotify::getMainIcon(bool hasNew)
return hasNew ? FilesDefs::getIconFromQtResourcePath(":/icons/png/posted-notify.png") : FilesDefs::getIconFromQtResourcePath(":/icons/png/posted.png"); return hasNew ? FilesDefs::getIconFromQtResourcePath(":/icons/png/posted-notify.png") : FilesDefs::getIconFromQtResourcePath(":/icons/png/posted.png");
} }
QString PostedUserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 new board posts") : tr("You have %1 new board post");
}
QString PostedUserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 new board post") : tr("%1 new board post");
}
void PostedUserNotify::iconClicked() void PostedUserNotify::iconClicked()
{ {
MainWindow::showWindow(MainWindow::Posted); MainWindow::showWindow(MainWindow::Posted);

View File

@ -28,15 +28,18 @@ class PostedUserNotify : public GxsUserNotify
Q_OBJECT Q_OBJECT
public: public:
PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); explicit PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("new board post(s)"); }
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual void iconClicked();
virtual QString getTrayMessage(bool plural) override;
virtual QString getNotifyMessage(bool plural) override;
virtual void iconClicked() override;
}; };
#endif // POSTEDUSERNOTIFY_H #endif // POSTEDUSERNOTIFY_H

View File

@ -136,12 +136,12 @@ unsigned int ChatLobbyUserNotify::getNewCount()
QString ChatLobbyUserNotify::getTrayMessage(bool plural) QString ChatLobbyUserNotify::getTrayMessage(bool plural)
{ {
return plural ? tr("You have %1 new messages") : tr("You have %1 new message"); return plural ? tr("You have %1 mentions") : tr("You have %1 mention");
} }
QString ChatLobbyUserNotify::getNotifyMessage(bool plural) QString ChatLobbyUserNotify::getNotifyMessage(bool plural)
{ {
return plural ? tr("%1 new messages") : tr("%1 new message"); return plural ? tr("%1 mentions") : tr("%1 mention");
} }
void ChatLobbyUserNotify::iconClicked() void ChatLobbyUserNotify::iconClicked()

View File

@ -63,7 +63,6 @@ public:
QString textToNotify() { return _textToNotify.join("\n");} QString textToNotify() { return _textToNotify.join("\n");}
void setTextCaseSensitive(bool value); void setTextCaseSensitive(bool value);
bool isTextCaseSensitive() {return _bTextCaseSensitive;} bool isTextCaseSensitive() {return _bTextCaseSensitive;}
virtual QString textInfo() const override { return tr("mention(s)"); }
signals: signals:
void countChanged(ChatLobbyId id, unsigned int count); void countChanged(ChatLobbyId id, unsigned int count);

View File

@ -94,6 +94,16 @@ unsigned int ChatUserNotify::getNewCount()
return sum; return sum;
} }
QString ChatUserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 mentions") : tr("You have %1 mention");
}
QString ChatUserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 mentions") : tr("%1 mention");
}
void ChatUserNotify::iconClicked() void ChatUserNotify::iconClicked()
{ {
ChatDialog *chatDialog = NULL; ChatDialog *chatDialog = NULL;

View File

@ -34,23 +34,26 @@ class ChatUserNotify : public UserNotify
Q_OBJECT Q_OBJECT
public: public:
static void getPeersWithWaitingChat(std::vector<RsPeerId>& peers); static void getPeersWithWaitingChat(std::vector<RsPeerId>& peers);
static void clearWaitingChat(ChatId id); static void clearWaitingChat(ChatId id);
ChatUserNotify(QObject *parent = 0); ChatUserNotify(QObject *parent = 0);
~ChatUserNotify(); ~ChatUserNotify();
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("mention(s)"); }
private slots: private slots:
void chatMessageReceived(ChatMessage msg); void chatMessageReceived(ChatMessage msg);
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual unsigned int getNewCount(); virtual unsigned int getNewCount() override;
virtual void iconClicked();
virtual QString getTrayMessage(bool plural) override;
virtual QString getNotifyMessage(bool plural) override;
virtual void iconClicked() override;
}; };
#endif // CHATUSERNOTIFY_H #endif // CHATUSERNOTIFY_H

View File

@ -26,17 +26,13 @@
#include "rshare.h" #include "rshare.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
UserNotify::UserNotify(QObject *parent) : UserNotify::UserNotify(QObject *parent)
QObject(parent) : QObject(parent)
, mMainToolButton(nullptr), mMainAction(nullptr)
, mListItem(nullptr), mTrayIcon(nullptr)
, mNotifyIcon(nullptr), mNewCount(0)
, mLastBlinking(false)
{ {
mMainToolButton = NULL;
mMainAction = NULL;
mListItem = NULL;
mTrayIcon = NULL;
mNotifyIcon = NULL;
mNewCount = 0;
mLastBlinking = false;
connect(rApp, SIGNAL(blink(bool)), this, SLOT(blink(bool))); connect(rApp, SIGNAL(blink(bool)), this, SLOT(blink(bool)));
} }
@ -88,12 +84,11 @@ void UserNotify::setNotifyEnabled(bool enabled, bool combined, bool blink)
Settings->endGroup(); Settings->endGroup();
} }
void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction, QListWidgetItem *listItem,const QString& subtext) void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction, QListWidgetItem *listItem)
{ {
mMainAction = mainAction; mMainAction = mainAction;
if (mMainAction) { if (mMainAction) {
mButtonText = mMainAction->text(); mButtonText = mMainAction->text();
mButtonText2 = subtext;
if (mainToolBar) { if (mainToolBar) {
mMainToolButton = dynamic_cast<QToolButton*>(mainToolBar->widgetForAction(mMainAction)); mMainToolButton = dynamic_cast<QToolButton*>(mainToolBar->widgetForAction(mMainAction));
} }
@ -106,14 +101,14 @@ void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction, QListWid
void UserNotify::createIcons(QMenu *notifyMenu) void UserNotify::createIcons(QMenu *notifyMenu)
{ {
#define DELETE_OBJECT(x) if (x) { delete(x); x = NULL; } #define DELETE_OBJECT(x) if (x) { delete(x); x = nullptr; }
/* Create systray icons or actions */ /* Create systray icons or actions */
if (notifyEnabled()) { if (notifyEnabled()) {
if (notifyCombined()) { if (notifyCombined()) {
DELETE_OBJECT(mTrayIcon); DELETE_OBJECT(mTrayIcon);
if (mNotifyIcon == NULL) { if (mNotifyIcon == nullptr) {
mNotifyIcon = notifyMenu->addAction(getIcon(), "", this, SLOT(trayIconClicked())); mNotifyIcon = notifyMenu->addAction(getIcon(), "", this, SLOT(trayIconClicked()));
mNotifyIcon->setVisible(false); mNotifyIcon->setVisible(false);
connect(mNotifyIcon, SIGNAL(hovered()), this, SLOT(trayIconHovered())); connect(mNotifyIcon, SIGNAL(hovered()), this, SLOT(trayIconHovered()));
@ -168,16 +163,15 @@ void UserNotify::update()
mMainAction->setIcon(getMainIcon(count > 0)); mMainAction->setIcon(getMainIcon(count > 0));
if(count > 0) if(count > 0)
{ {
if(!mButtonText2.isNull())
mMainAction->setToolTip(QString("%1 (%2 %3)").arg(mButtonText).arg(count).arg(mButtonText2));
else
mMainAction->setToolTip(QString("%1 (%2)").arg(mButtonText).arg(count));
mMainAction->setText(QString("%1 (%2)").arg(mButtonText).arg(count)); mMainAction->setText(QString("%1 (%2)").arg(mButtonText).arg(count));
} mMainAction->setToolTip(QString("%1 (%2)").arg(mButtonText, getNotifyMessage(count > 1).arg(count) ));
else }
else
{
mMainAction->setText(mButtonText); mMainAction->setText(mButtonText);
mMainAction->setToolTip(mButtonText);
}
QFont font = mMainAction->font(); QFont font = mMainAction->font();
font.setBold(count > 0); font.setBold(count > 0);

View File

@ -37,17 +37,13 @@ public:
UserNotify(QObject *parent = 0); UserNotify(QObject *parent = 0);
virtual ~UserNotify(); virtual ~UserNotify();
void initialize(QToolBar *mainToolBar, QAction *mainAction, QListWidgetItem *listItem,const QString& subtext); void initialize(QToolBar *mainToolBar, QAction *mainAction, QListWidgetItem *listItem);
void createIcons(QMenu *notifyMenu); void createIcons(QMenu *notifyMenu);
QSystemTrayIcon* getTrayIcon(){ return mTrayIcon;} QSystemTrayIcon* getTrayIcon(){ return mTrayIcon;}
QAction* getNotifyIcon(){ return mNotifyIcon;} QAction* getNotifyIcon(){ return mNotifyIcon;}
virtual bool hasSetting(QString */*name*/, QString */*group*/) { return false; } virtual bool hasSetting(QString */*name*/, QString */*group*/) { return false; }
// UserNotify is used to display tooltips when some services have no messages and so on, in the format of "Name (43242 new messages)"
// This method is used to pass the string that comes after the number.
virtual QString textInfo() const { return QString() ; }
bool notifyEnabled(); bool notifyEnabled();
bool notifyCombined(); bool notifyCombined();
bool notifyBlink(); bool notifyBlink();
@ -87,7 +83,6 @@ private:
QAction *mNotifyIcon; QAction *mNotifyIcon;
unsigned int mNewCount; unsigned int mNewCount;
QString mButtonText; QString mButtonText;
QString mButtonText2;
bool mLastBlinking; bool mLastBlinking;
}; };

View File

@ -45,3 +45,14 @@ unsigned int NewsFeedUserNotify::getNewCount()
{ {
return mNewFeedCount; return mNewFeedCount;
} }
QString NewsFeedUserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 logged events") : tr("You have %1 logged event");
}
QString NewsFeedUserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 logged events") : tr("%1 logged event");
}

View File

@ -29,16 +29,18 @@ class NewsFeedUserNotify : public UserNotify
{ {
Q_OBJECT Q_OBJECT
virtual QString textInfo() const override { return tr("logged event(s)"); }
public: public:
NewsFeedUserNotify(NewsFeed *newsFeed, QObject *parent = 0); explicit NewsFeedUserNotify(NewsFeed *newsFeed, QObject *parent = 0);
private slots: private slots:
void newsFeedChanged(int count); void newsFeedChanged(int count);
private: private:
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual unsigned int getNewCount(); virtual unsigned int getNewCount() override;
virtual QString getTrayMessage(bool plural) override;
virtual QString getNotifyMessage(bool plural) override;
private: private:
unsigned int mNewFeedCount; unsigned int mNewFeedCount;

View File

@ -29,15 +29,15 @@ class GxsChannelUserNotify : public GxsUserNotify
Q_OBJECT Q_OBJECT
public: public:
GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); explicit GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("new message(s)"); }
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual void iconClicked();
virtual void iconClicked() override;
}; };
#endif // GXSCHANNELUSERNOTIFY_H #endif // GXSCHANNELUSERNOTIFY_H

View File

@ -28,15 +28,15 @@ class GxsForumUserNotify : public GxsUserNotify
Q_OBJECT Q_OBJECT
public: public:
GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); explicit GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("new message(s)"); }
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual void iconClicked();
virtual void iconClicked() override;
}; };
#endif // FORUMUSERNOTIFY_H #endif // FORUMUSERNOTIFY_H

View File

@ -58,6 +58,16 @@ unsigned int MessageUserNotify::getNewCount()
return newInboxCount; return newInboxCount;
} }
QString MessageUserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 new mails") : tr("You have %1 new mail");
}
QString MessageUserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 new mails") : tr("%1 new mail");
}
void MessageUserNotify::iconClicked() void MessageUserNotify::iconClicked()
{ {
MainWindow::showWindow(MainWindow::Messages); MainWindow::showWindow(MainWindow::Messages);

View File

@ -30,14 +30,17 @@ class MessageUserNotify : public UserNotify
public: public:
MessageUserNotify(QObject *parent = 0); MessageUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group); virtual bool hasSetting(QString *name, QString *group) override;
virtual QString textInfo() const override { return tr("new mail(s)"); }
private: private:
virtual QIcon getIcon(); virtual QIcon getIcon() override;
virtual QIcon getMainIcon(bool hasNew); virtual QIcon getMainIcon(bool hasNew) override;
virtual unsigned int getNewCount(); virtual unsigned int getNewCount() override;
virtual void iconClicked();
virtual QString getTrayMessage(bool plural) override;
virtual QString getNotifyMessage(bool plural) override;
virtual void iconClicked() override;
}; };
#endif // MESSAGEUSERNOTIFY_H #endif // MESSAGEUSERNOTIFY_H