Reworked notification code in system tray.

Added a base class and a possibility for the main dialogs and the plugins (derived from MainPage) to provide a notifier.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5381 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-08-05 20:12:55 +00:00
parent 049b4bd577
commit b21e66241b
30 changed files with 1040 additions and 539 deletions

View File

@ -40,6 +40,7 @@
#include "channels/CreateChannelMsg.h"
#include "channels/EditChanDetails.h"
#include "channels/ShareKey.h"
#include "channels/ChannelUserNotify.h"
#include "notifyqt.h"
#include "RetroShareLink.h"
@ -113,6 +114,11 @@ ChannelFeed::~ChannelFeed()
processSettings(false);
}
UserNotify *ChannelFeed::getUserNotify(QObject *parent)
{
return new ChannelUserNotify(parent);
}
void ChannelFeed::processSettings(bool load)
{
Settings->beginGroup(QString("ChannelFeed"));

View File

@ -48,6 +48,8 @@ public:
/** Default Destructor */
~ChannelFeed();
virtual UserNotify *getUserNotify(QObject *parent);
virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(std::string peerId);

View File

@ -31,6 +31,7 @@
#include "forums/CreateForumMsg.h"
#include "forums/ForumDetails.h"
#include "forums/EditForumDetails.h"
#include "forums/ForumUserNotify.h"
#include "msgs/MessageComposer.h"
#include "settings/rsharesettings.h"
#include "common/Emoticons.h"
@ -237,6 +238,11 @@ ForumsDialog::~ForumsDialog()
processSettings(false);
}
UserNotify *ForumsDialog::getUserNotify(QObject *parent)
{
return new ForumUserNotify(parent);
}
void ForumsDialog::processSettings(bool bLoad)
{
m_bProcessSettings = true;

View File

@ -40,6 +40,8 @@ public:
ForumsDialog(QWidget *parent = 0);
~ForumsDialog();
virtual UserNotify *getUserNotify(QObject *parent);
bool navigate(const std::string& forumId, const std::string& msgId);
/* overloaded from RsAuthUpdatePage */

View File

@ -42,6 +42,7 @@
#include "common/vmessagebox.h"
#include "common/PeerDefs.h"
#include "chat/ChatDialog.h"
#include "chat/ChatUserNotify.h"
#include "connect/ConfCertDialog.h"
#include "connect/ConnectFriendWizard.h"
#include "forums/CreateForum.h"
@ -230,6 +231,11 @@ FriendsDialog::~FriendsDialog ()
}
}
UserNotify *FriendsDialog::getUserNotify(QObject *parent)
{
return new ChatUserNotify(parent);
}
void FriendsDialog::processSettings(bool bLoad)
{
Settings->beginGroup(QString("FriendsDialog"));

View File

@ -43,6 +43,8 @@ public:
/** Default Destructor */
~FriendsDialog ();
virtual UserNotify *getUserNotify(QObject *parent);
virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage
static ChatTabWidget *getTabWidget();

View File

@ -58,6 +58,7 @@
#include "RetroShareLink.h"
#include "SoundManager.h"
#include "notifyqt.h"
#include "common/UserNotify.h"
#ifdef UNFINISHED
#include "unfinished/ApplicationWindow.h"
@ -185,16 +186,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
onlineCount = 0;
notifyMenu = NULL;
trayIconMessages = NULL;
trayIconForums = NULL;
trayIconChannels = NULL;
trayIconChat = NULL;
trayIconTransfers = NULL;
trayActionMessages = NULL;
trayActionForums = NULL;
trayActionChannels = NULL;
trayActionChat = NULL;
trayActionTransfers = NULL;
/* Calculate only once */
RsPeerDetails pd;
@ -243,36 +234,44 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
/* load the StyleSheet*/
Rshare::loadStyleSheet(Rshare::stylesheet());
QList<QPair<MainPage*, QAction*> > notify;
/* Create the Main pages and actions */
QActionGroup *grp = new QActionGroup(this);
QAction *action;
ui.stackPages->add(networkDialog = new NetworkDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_NETWORK2), tr("Network"), grp));
ui.stackPages->add(friendsDialog = new FriendsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_PEERS), tr("Friends"), grp));
action = createPageAction(QIcon(IMAGE_PEERS), tr("Friends"), grp));
notify.push_back(QPair<MainPage*, QAction*>(friendsDialog, action));
ui.stackPages->add(searchDialog = new SearchDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SEARCH), tr("Search"), grp));
ui.stackPages->add(transfersDialog = new TransfersDialog(ui.stackPages),
transferAction = createPageAction(QIcon(IMAGE_TRANSFERS), tr("Transfers"), grp));
action = createPageAction(QIcon(IMAGE_TRANSFERS), tr("Transfers"), grp));
notify.push_back(QPair<MainPage*, QAction*>(transfersDialog, action));
ui.stackPages->add(sharedfilesDialog = new SharedFilesDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_FILES), tr("Files"), grp));
ui.stackPages->add(messagesDialog = new MessagesDialog(ui.stackPages),
messageAction = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
action = createPageAction(QIcon(IMAGE_MESSAGES), tr("Messages"), grp));
notify.push_back(QPair<MainPage*, QAction*>(messagesDialog, action));
ui.stackPages->add(channelFeed = new ChannelFeed(ui.stackPages),
channelAction = createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
action = createPageAction(QIcon(IMAGE_CHANNELS), tr("Channels"), grp));
notify.push_back(QPair<MainPage*, QAction*>(channelFeed, action));
#ifdef BLOGS
ui.stackPages->add(blogsFeed = new BlogsDialog(ui.stackPages), createPageAction(QIcon(IMAGE_BLOGS), tr("Blogs"), grp));
#endif
ui.stackPages->add(forumsDialog = new ForumsDialog(ui.stackPages),
forumAction = createPageAction(QIcon(IMAGE_FORUMS), tr("Forums"), grp));
action = createPageAction(QIcon(IMAGE_FORUMS), tr("Forums"), grp));
notify.push_back(QPair<MainPage*, QAction*>(forumsDialog, action));
std::cerr << "Looking for interfaces in existing plugins:" << std::endl;
for(int i = 0;i<rsPlugins->nbPlugins();++i)
@ -287,7 +286,10 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
icon = QIcon(":images/extension_48.png") ;
std::cerr << " Addign widget page for plugin " << rsPlugins->plugin(i)->getPluginName() << std::endl;
ui.stackPages->add(rsPlugins->plugin(i)->qt_page(), createPageAction(icon, QString::fromUtf8(rsPlugins->plugin(i)->getPluginName().c_str()), grp));
MainPage *pluginPage = rsPlugins->plugin(i)->qt_page();
QAction *pluginAction = createPageAction(icon, QString::fromUtf8(rsPlugins->plugin(i)->getPluginName().c_str()), grp);
ui.stackPages->add(pluginPage, pluginAction);
notify.push_back(QPair<MainPage*, QAction*>(pluginPage, pluginAction));
}
else if(rsPlugins->plugin(i) == NULL)
std::cerr << " No plugin object !" << std::endl;
@ -366,6 +368,18 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
/* Creates a tray icon with a context menu and adds it to the system's * notification area. */
createTrayIcon();
QList<QPair<MainPage*, QAction*> >::iterator notifyIt;
for (notifyIt = notify.begin(); notifyIt != notify.end(); ++notifyIt) {
UserNotify *userNotify = notifyIt->first->getUserNotify(this);
if (userNotify) {
userNotify->initialize(notifyIt->second);
connect(userNotify, SIGNAL(countChanged()), this, SLOT(updateTrayCombine()));
userNotifyList.push_back(userNotify);
}
}
createNotifyIcons();
/* caclulate friend count */
updateFriends();
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateFriends()));
@ -471,123 +485,24 @@ void MainWindow::createTrayIcon()
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
createNotifyIcons();
}
void MainWindow::createNotifyIcons()
{
#define DELETE_OBJECT(x) if (x) { delete(x); x = NULL; }
int notifyFlag = Settings->getTrayNotifyFlags();
/* Delete notify actions */
DELETE_OBJECT(trayActionMessages);
DELETE_OBJECT(trayActionForums);
DELETE_OBJECT(trayActionChannels);
DELETE_OBJECT(trayActionChat);
DELETE_OBJECT(trayActionTransfers);
/* Create systray icons or actions */
if (notifyFlag & TRAYNOTIFY_MESSAGES) {
if (notifyFlag & TRAYNOTIFY_MESSAGES_COMBINED) {
DELETE_OBJECT(trayIconMessages);
trayActionMessages = notifyMenu->addAction(QIcon(":/images/newmsg.png"), "", this, SLOT(trayIconMessagesClicked()));
trayActionMessages->setVisible(false);
// trayActionMessages->setData(tr("Messages"));
} else if (trayIconMessages == NULL) {
// Create the tray icon for messages
trayIconMessages = new QSystemTrayIcon(this);
trayIconMessages->setIcon(QIcon(":/images/newmsg.png"));
connect(trayIconMessages, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconMessagesClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(trayIconMessages);
DELETE_OBJECT(trayActionMessages);
/* create notify icons */
QList<UserNotify*>::iterator it;
for (it = userNotifyList.begin(); it != userNotifyList.end(); ++it) {
UserNotify *userNotify = *it;
userNotify->createIcons(notifyMenu);
userNotify->updateIcon();
}
if (notifyFlag & TRAYNOTIFY_FORUMS) {
if (notifyFlag & TRAYNOTIFY_FORUMS_COMBINED) {
DELETE_OBJECT(trayIconForums);
trayActionForums = notifyMenu->addAction(QIcon(":/images/konversation16.png"), "", this, SLOT(trayIconForumsClicked()));
trayActionForums->setVisible(false);
// trayActionForums->setData(tr("Forums"));
} else if (trayIconForums == NULL) {
// Create the tray icon for forums
trayIconForums = new QSystemTrayIcon(this);
trayIconForums->setIcon(QIcon(":/images/konversation16.png"));
connect(trayIconForums, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconForumsClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(trayIconForums);
DELETE_OBJECT(trayActionForums);
}
if (notifyFlag & TRAYNOTIFY_CHANNELS) {
if (notifyFlag & TRAYNOTIFY_CHANNELS_COMBINED) {
DELETE_OBJECT(trayIconChannels);
trayActionChannels = notifyMenu->addAction(QIcon(":/images/channels16.png"), "", this, SLOT(trayIconChannelsClicked()));
trayActionChannels->setVisible(false);
// trayActionChannels->setData(tr("Channels"));
} else if (trayIconChannels == NULL) {
// Create the tray icon for channels
trayIconChannels = new QSystemTrayIcon(this);
trayIconChannels->setIcon(QIcon(":/images/channels16.png"));
connect(trayIconChannels, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconChannelsClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(trayIconChannels);
DELETE_OBJECT(trayActionChannels);
}
if (notifyFlag & TRAYNOTIFY_PRIVATECHAT) {
if (notifyFlag & TRAYNOTIFY_PRIVATECHAT_COMBINED) {
DELETE_OBJECT(trayIconChat);
trayActionChat = notifyMenu->addAction(QIcon(":/images/chat.png"), "", this, SLOT(trayIconChatClicked()));
trayActionChat->setVisible(false);
// trayActionChat->setData(tr("Chat"));
} else if (trayIconChat == NULL) {
// Create the tray icon for chat
trayIconChat = new QSystemTrayIcon(this);
trayIconChat->setIcon(QIcon(":/images/chat.png"));
connect(trayIconChat, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconChatClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(trayIconChat);
DELETE_OBJECT(trayActionChat);
}
if (notifyFlag & TRAYNOTIFY_TRANSFERS) {
if (notifyFlag & TRAYNOTIFY_TRANSFERS_COMBINED) {
DELETE_OBJECT(trayIconTransfers);
trayActionTransfers = notifyMenu->addAction(QIcon(":/images/ktorrent32.png"), "", this, SLOT(trayIconTransfersClicked()));
trayActionTransfers->setVisible(false);
// trayActionTransfers->setData(tr("Transfers"));
} else if (trayIconTransfers == NULL) {
// Create the tray icon for transfers
trayIconTransfers = new QSystemTrayIcon(this);
trayIconTransfers->setIcon(QIcon(":/images/ktorrent32.png"));
connect(trayIconTransfers, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconTransfersClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(trayIconTransfers);
DELETE_OBJECT(trayActionTransfers);
}
/* call once */
updateMessages();
updateForums();
updateChannels(NOTIFY_TYPE_ADD);
privateChatChanged(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, 0);
// transfer
#undef DELETE_OBJECT
}
const QList<UserNotify*> &MainWindow::getUserNotifyList()
{
return userNotifyList;
}
/*static*/ void MainWindow::displayLobbySystrayMsg(const QString& title,const QString& msg)
{
if (_instance == NULL)
@ -627,169 +542,6 @@ void MainWindow::displaySystrayMsg(const QString& title,const QString& msg)
trayIcon->showMessage(title, msg, QSystemTrayIcon::Information, 3000);
}
void MainWindow::updateMessages()
{
unsigned int newInboxCount = 0;
rsMsgs->getMessageCount (NULL, &newInboxCount, NULL, NULL, NULL, NULL);
if(newInboxCount) {
messageAction->setIcon(QIcon(QPixmap(":/images/messages_new.png"))) ;
} else {
messageAction->setIcon(QIcon(QPixmap(":/images/evolution.png"))) ;
}
if (trayIconMessages) {
if (newInboxCount) {
if (newInboxCount > 1) {
trayIconMessages->setToolTip("RetroShare\n" + tr("You have %1 new messages").arg(newInboxCount));
} else {
trayIconMessages->setToolTip("RetroShare\n" + tr("You have %1 new message").arg(newInboxCount));
}
trayIconMessages->show();
} else {
trayIconMessages->hide();
}
}
if (trayActionMessages) {
trayActionMessages->setData(newInboxCount);
if (newInboxCount) {
if (newInboxCount > 1) {
trayActionMessages->setText(tr("%1 new messages").arg(newInboxCount));
} else {
trayActionMessages->setText(tr("%1 new message").arg(newInboxCount));
}
trayActionMessages->setVisible(true);
} else {
trayActionMessages->setVisible(false);
}
}
updateTrayCombine();
}
void MainWindow::updateForums()
{
unsigned int newMessageCount = 0;
unsigned int unreadMessageCount = 0;
rsForums->getMessageCount("", newMessageCount, unreadMessageCount);
if (newMessageCount) {
forumAction->setIcon(QIcon(":/images/konversation_new.png")) ;
} else {
forumAction->setIcon(QIcon(IMAGE_FORUMS)) ;
}
if (trayIconForums) {
if (newMessageCount) {
if (newMessageCount > 1) {
trayIconForums->setToolTip("RetroShare\n" + tr("You have %1 new messages").arg(newMessageCount));
} else {
trayIconForums->setToolTip("RetroShare\n" + tr("You have %1 new message").arg(newMessageCount));
}
trayIconForums->show();
} else {
trayIconForums->hide();
}
}
if (trayActionForums) {
trayActionForums->setData(newMessageCount);
if (newMessageCount) {
if (newMessageCount > 1) {
trayActionForums->setText(tr("%1 new messages").arg(newMessageCount));
} else {
trayActionForums->setText(tr("%1 new message").arg(newMessageCount));
}
trayActionForums->setVisible(true);
} else {
trayActionForums->setVisible(false);
}
}
updateTrayCombine();
}
void MainWindow::updateChannels(int /*type*/)
{
unsigned int newMessageCount = 0;
unsigned int unreadMessageCount = 0;
rsChannels->getMessageCount("", newMessageCount, unreadMessageCount);
if (newMessageCount) {
channelAction->setIcon(QIcon(":/images/channels_new32.png")) ;
} else {
channelAction->setIcon(QIcon(IMAGE_CHANNELS)) ;
}
if (trayIconChannels) {
if (newMessageCount) {
if (newMessageCount > 1) {
trayIconChannels->setToolTip("RetroShare\n" + tr("You have %1 new messages").arg(newMessageCount));
} else {
trayIconChannels->setToolTip("RetroShare\n" + tr("You have %1 new message").arg(newMessageCount));
}
trayIconChannels->show();
} else {
trayIconChannels->hide();
}
}
if (trayActionChannels) {
trayActionChannels->setData(newMessageCount);
if (newMessageCount) {
if (newMessageCount > 1) {
trayActionChannels->setText(tr("%1 new messages").arg(newMessageCount));
} else {
trayActionChannels->setText(tr("%1 new message").arg(newMessageCount));
}
trayActionChannels->setVisible(true);
} else {
trayActionChannels->setVisible(false);
}
}
updateTrayCombine();
}
void MainWindow::updateTransfers(int count)
{
if (count) {
transferAction->setIcon(QIcon(":/images/transfers_new32.png")) ;
} else {
transferAction->setIcon(QIcon(IMAGE_TRANSFERS)) ;
}
if (trayIconTransfers) {
if (count) {
if (count > 1) {
trayIconTransfers->setToolTip("RetroShare\n" + tr("You have %1 completed downloads").arg(count));
} else {
trayIconTransfers->setToolTip("RetroShare\n" + tr("You have %1 completed download").arg(count));
}
trayIconTransfers->show();
} else {
trayIconTransfers->hide();
}
}
if (trayActionTransfers) {
trayActionTransfers->setData(count);
if (count) {
if (count > 1) {
trayActionTransfers->setText(tr("%1 completed downloads").arg(count));
} else {
trayActionTransfers->setText(tr("%1 completed download").arg(count));
}
trayActionTransfers->setVisible(true);
} else {
trayActionTransfers->setVisible(false);
}
}
updateTrayCombine();
}
void MainWindow::updateTrayCombine()
{
notifyToolTip.clear();
@ -899,46 +651,6 @@ void MainWindow::updateFriends()
trayIcon->setIcon(icon);
}
void MainWindow::privateChatChanged(int list, int type)
{
/* first process the chat messages */
ChatDialog::chatChanged(list, type);
if (list == NOTIFY_LIST_PRIVATE_INCOMING_CHAT) {
/* than count the chat messages */
int chatCount = rsMsgs->getPrivateChatQueueCount(true);
if (trayIconChat) {
if (chatCount) {
if (chatCount > 1) {
trayIconChat->setToolTip("RetroShare\n" + tr("You have %1 new messages").arg(chatCount));
} else {
trayIconChat->setToolTip("RetroShare\n" + tr("You have %1 new message").arg(chatCount));
}
trayIconChat->show();
} else {
trayIconChat->hide();
}
}
if (trayActionChat) {
trayActionChat->setData(chatCount);
if (chatCount) {
if (chatCount > 1) {
trayActionChat->setText(tr("%1 new messages").arg(chatCount));
} else {
trayActionChat->setText(tr("%1 new message").arg(chatCount));
}
trayActionChat->setVisible(true);
} else {
trayActionChat->setVisible(false);;
}
}
updateTrayCombine();
}
}
void MainWindow::postModDirectories(bool update_local)
{
RSettingsWin::postModDirectories(update_local);
@ -1321,49 +1033,6 @@ void MainWindow::toggleVisibility(QSystemTrayIcon::ActivationReason e)
}
}
void MainWindow::trayIconMessagesClicked(QSystemTrayIcon::ActivationReason e)
{
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
showMess();
}
}
void MainWindow::trayIconForumsClicked(QSystemTrayIcon::ActivationReason e)
{
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
showWindow(MainWindow::Forums);
}
}
void MainWindow::trayIconChannelsClicked(QSystemTrayIcon::ActivationReason e)
{
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
showWindow(MainWindow::Channels);
}
}
void MainWindow::trayIconChatClicked(QSystemTrayIcon::ActivationReason e)
{
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
ChatDialog *chatDialog = NULL;
std::list<std::string> ids;
if (rsMsgs->getPrivateChatQueueIds(true, ids) && ids.size()) {
chatDialog = ChatDialog::getChat(ids.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
}
if (chatDialog == NULL) {
showWindow(MainWindow::Friends);
}
}
}
void MainWindow::trayIconTransfersClicked(QSystemTrayIcon::ActivationReason e)
{
if(e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
showWindow(MainWindow::Transfers);
}
}
void MainWindow::toggleVisibilitycontextmenu()
{
if (isVisible() && !isMinimized())

View File

@ -103,6 +103,8 @@ public:
/** get page */
static MainPage *getPage (Page page);
const QList<UserNotify*> &getUserNotifyList();
/* A Bit of a Hack... but public variables for
* the dialogs, so we can add them to the
* Notify Class...
@ -145,11 +147,6 @@ public slots:
void postModDirectories(bool update_local);
void displayDiskSpaceWarning(int loc,int size_limit_mb) ;
void checkAndSetIdle(int idleTime);
void updateMessages();
void updateForums();
void updateChannels(int type);
void updateTransfers(int count);
void privateChatChanged(int list, int type);
void linkActivated(const QUrl &url);
@ -171,13 +168,6 @@ private slots:
void toggleVisibility(QSystemTrayIcon::ActivationReason e);
void toggleVisibilitycontextmenu();
/* default parameter for connect with the actions of the combined systray icon */
void trayIconMessagesClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void trayIconForumsClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void trayIconChannelsClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void trayIconChatClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
void trayIconTransfersClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
/** Toolbar fns. */
void addFriend();
void showMessengerWindow();
@ -207,12 +197,11 @@ private slots:
void doQuit();
void on_actionQuick_Start_Wizard_activated();
void updateTrayCombine();
private:
void createTrayIcon();
void createNotifyIcons();
void updateTrayCombine();
static MainWindow *_instance;
/** A BandwidthGraph object which handles monitoring RetroShare bandwidth usage */
@ -226,19 +215,10 @@ private:
QString nameAndLocation;
QSystemTrayIcon *trayIcon;
QSystemTrayIcon *trayIconMessages;
QSystemTrayIcon *trayIconForums;
QSystemTrayIcon *trayIconChannels;
QSystemTrayIcon *trayIconChat;
QSystemTrayIcon *trayIconTransfers;
QMenu *notifyMenu;
QString notifyToolTip;
QAction *trayActionMessages;
QAction *trayActionForums;
QAction *trayActionChannels;
QAction *trayActionChat;
QAction *trayActionTransfers;
QAction *toggleVisibilityAction, *toolAct;
QList<UserNotify*> userNotifyList;
PeerStatus *peerstatus;
NATStatus *natstatus;
@ -248,11 +228,6 @@ private:
HashingStatus *hashingstatus;
QComboBox *statusComboBox;
QAction *messageAction;
QAction *forumAction;
QAction *channelAction;
QAction *transferAction;
/* Status */
std::set <QObject*> m_apStatusObjects; // added objects for status
bool m_bStatusLoadDone;

View File

@ -29,6 +29,7 @@
#include "msgs/MessageComposer.h"
#include "msgs/MessageWidget.h"
#include "msgs/TagsMenu.h"
#include "msgs/MessageUserNotify.h"
#include "settings/rsharesettings.h"
#include "common/TagDefs.h"
#include "common/PeerDefs.h"
@ -316,6 +317,11 @@ MessagesDialog::~MessagesDialog()
processSettings(false);
}
UserNotify *MessagesDialog::getUserNotify(QObject *parent)
{
return new MessageUserNotify(parent);
}
void MessagesDialog::processSettings(bool load)
{
int messageTreeVersion = 2; // version number for the settings to solve problems when modifying the column count

View File

@ -39,6 +39,8 @@ public:
/** Default Destructor */
~MessagesDialog();
virtual UserNotify *getUserNotify(QObject *parent);
// replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ;

View File

@ -48,6 +48,7 @@
#include "settings/rsharesettings.h"
#include "util/misc.h"
#include "common/RsCollectionFile.h"
#include "transfers/TransferUserNotify.h"
#include <retroshare/rsfiles.h>
#include <retroshare/rspeers.h>
@ -399,6 +400,11 @@ TransfersDialog::~TransfersDialog()
processSettings(false);
}
UserNotify *TransfersDialog::getUserNotify(QObject *parent)
{
return new TransferUserNotify(parent);
}
void TransfersDialog::processSettings(bool bLoad)
{
m_bProcessSettings = true;

View File

@ -46,6 +46,8 @@ public:
TransfersDialog(QWidget *parent = 0);
~TransfersDialog();
virtual UserNotify *getUserNotify(QObject *parent);
// replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ;
virtual void updateDisplay() ; // derived from RsAutoUpdateWidget

View File

@ -0,0 +1,93 @@
/****************************************************************
* 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 "ChannelUserNotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
#include <retroshare/rschannels.h>
ChannelUserNotify::ChannelUserNotify(QObject *parent) :
UserNotify(parent)
{
connect(NotifyQt::getInstance(), SIGNAL(channelsChanged(int)), this, SLOT(updateIcon()), Qt::QueuedConnection);
}
bool ChannelUserNotify::hasSetting(QString &name)
{
name = tr("Channel Post");
return true;
}
bool ChannelUserNotify::notifyEnabled()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_CHANNELS);
}
bool ChannelUserNotify::notifyCombined()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_CHANNELS_COMBINED);
}
void ChannelUserNotify::setNotifyEnabled(bool enabled, bool combined)
{
uint notifyFlags = Settings->getTrayNotifyFlags();
if (enabled) {
notifyFlags |= TRAYNOTIFY_CHANNELS;
} else {
notifyFlags &= ~TRAYNOTIFY_CHANNELS;
}
if (combined) {
notifyFlags |= TRAYNOTIFY_CHANNELS_COMBINED;
} else {
notifyFlags &= ~TRAYNOTIFY_CHANNELS_COMBINED;
}
Settings->setTrayNotifyFlags(notifyFlags);
}
QIcon ChannelUserNotify::getIcon()
{
return QIcon(":/images/channels16.png");
}
QIcon ChannelUserNotify::getMainIcon(bool hasNew)
{
return hasNew ? QIcon(":/images/channels_new32.png") : QIcon(":/images/channels.png");
}
unsigned int ChannelUserNotify::getNewCount()
{
unsigned int newMessageCount = 0;
unsigned int unreadMessageCount = 0;
rsChannels->getMessageCount("", newMessageCount, unreadMessageCount);
return newMessageCount;
}
void ChannelUserNotify::iconClicked()
{
MainWindow::showWindow(MainWindow::Channels);
}

View File

@ -0,0 +1,46 @@
/****************************************************************
* 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 CHANNELUSERNOTIFY_H
#define CHANNELUSERNOTIFY_H
#include "gui/common/UserNotify.h"
class ChannelUserNotify : public UserNotify
{
Q_OBJECT
public:
ChannelUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString &name);
virtual bool notifyEnabled();
virtual bool notifyCombined();
virtual void setNotifyEnabled(bool enabled, bool combined);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);
virtual unsigned int getNewCount();
virtual void iconClicked();
};
#endif // CHANNELUSERNOTIFY_H

View File

@ -0,0 +1,110 @@
/****************************************************************
* 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 "ChatUserNotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
#include "gui/chat/ChatDialog.h"
#include <retroshare/rsnotify.h>
#include <retroshare/rsmsgs.h>
ChatUserNotify::ChatUserNotify(QObject *parent) :
UserNotify(parent)
{
connect(NotifyQt::getInstance(), SIGNAL(privateChatChanged(int, int)), this, SLOT(privateChatChanged(int, int)));
}
bool ChatUserNotify::hasSetting(QString &name)
{
name = tr("Private Chat");
return true;
}
bool ChatUserNotify::notifyEnabled()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_PRIVATECHAT);
}
bool ChatUserNotify::notifyCombined()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_PRIVATECHAT_COMBINED);
}
void ChatUserNotify::setNotifyEnabled(bool enabled, bool combined)
{
uint notifyFlags = Settings->getTrayNotifyFlags();
if (enabled) {
notifyFlags |= TRAYNOTIFY_PRIVATECHAT;
} else {
notifyFlags &= ~TRAYNOTIFY_PRIVATECHAT;
}
if (combined) {
notifyFlags |= TRAYNOTIFY_PRIVATECHAT_COMBINED;
} else {
notifyFlags &= ~TRAYNOTIFY_PRIVATECHAT_COMBINED;
}
Settings->setTrayNotifyFlags(notifyFlags);
}
QIcon ChatUserNotify::getIcon()
{
return QIcon(":/images/chat.png");
}
QIcon ChatUserNotify::getMainIcon(bool hasNew)
{
return hasNew ? QIcon(":/images/groupchat.png") : QIcon(":/images/groupchat.png");
}
unsigned int ChatUserNotify::getNewCount()
{
return rsMsgs->getPrivateChatQueueCount(true);
}
void ChatUserNotify::iconClicked()
{
ChatDialog *chatDialog = NULL;
std::list<std::string> ids;
if (rsMsgs->getPrivateChatQueueIds(true, ids) && ids.size()) {
chatDialog = ChatDialog::getChat(ids.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
}
if (chatDialog == NULL) {
MainWindow::showWindow(MainWindow::Friends);
}
}
void ChatUserNotify::privateChatChanged(int list, int type)
{
/* first process the chat messages */
ChatDialog::chatChanged(list, type);
if (list == NOTIFY_LIST_PRIVATE_INCOMING_CHAT) {
updateIcon();
}
}

View File

@ -0,0 +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.
****************************************************************/
#ifndef CHATUSERNOTIFY_H
#define CHATUSERNOTIFY_H
#include "gui/common/UserNotify.h"
class ChatUserNotify : public UserNotify
{
Q_OBJECT
public:
ChatUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString &name);
virtual bool notifyEnabled();
virtual bool notifyCombined();
virtual void setNotifyEnabled(bool enabled, bool combined);
private slots:
void privateChatChanged(int list, int type);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);
virtual unsigned int getNewCount();
virtual void iconClicked();
};
#endif // CHATUSERNOTIFY_H

View File

@ -0,0 +1,94 @@
#include <QMenu>
#include "UserNotify.h"
UserNotify::UserNotify(QObject *parent) :
QObject(parent)
{
mMainIcon = NULL;
mTrayIcon = NULL;
mNotifyIcon = NULL;
newCount = 0;
}
void UserNotify::initialize(QAction *mainAction)
{
mMainIcon = mainAction;
}
void UserNotify::createIcons(QMenu *notifyMenu)
{
#define DELETE_OBJECT(x) if (x) { delete(x); x = NULL; }
/* Create systray icons or actions */
if (notifyEnabled()) {
if (notifyCombined()) {
DELETE_OBJECT(mTrayIcon);
if (mNotifyIcon == NULL) {
mNotifyIcon = notifyMenu->addAction(getIcon(), "", this, SLOT(trayIconClicked()));
mNotifyIcon->setVisible(false);
}
} else if (mTrayIcon == NULL) {
/* Create the tray icon for messages */
mTrayIcon = new QSystemTrayIcon(this);
mTrayIcon->setIcon(getIcon());
connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
}
} else {
DELETE_OBJECT(mTrayIcon);
DELETE_OBJECT(mNotifyIcon);
}
#undef DELETE_OBJECT
}
void UserNotify::updateIcon()
{
unsigned int count = getNewCount();
if (mMainIcon) {
mMainIcon->setIcon(getMainIcon(count > 0));
}
if (mTrayIcon) {
if (count) {
mTrayIcon->setToolTip("RetroShare\n" + getTrayMessage(count > 1).arg(count));
mTrayIcon->show();
} else {
mTrayIcon->hide();
}
}
if (mNotifyIcon) {
mNotifyIcon->setData(count);
if (count) {
mNotifyIcon->setText(getNotifyMessage(count > 1).arg(count));
mNotifyIcon->setVisible(true);
} else {
mNotifyIcon->setVisible(false);
}
}
if (newCount != count) {
emit countChanged();
}
count = newCount;
}
QString UserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 new messages") : tr("You have %1 new message");
}
QString UserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 new messages") : tr("%1 new message");
}
void UserNotify::trayIconClicked(QSystemTrayIcon::ActivationReason e)
{
if (e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
iconClicked();
}
}

View File

@ -0,0 +1,49 @@
#ifndef USERNOTIFY_H
#define USERNOTIFY_H
#include <QObject>
#include <QSystemTrayIcon>
class QAction;
class UserNotify : public QObject
{
Q_OBJECT
public:
UserNotify(QObject *parent = 0);
void initialize(QAction *mainAction);
void createIcons(QMenu *notifyMenu);
virtual bool hasSetting(QString &/*name*/) { return false; }
virtual bool notifyEnabled() { return false; }
virtual bool notifyCombined() { return false; }
virtual void setNotifyEnabled(bool /*enabled*/, bool /*combined*/) {}
signals:
void countChanged();
public slots:
void updateIcon();
private slots:
void trayIconClicked(QSystemTrayIcon::ActivationReason e = QSystemTrayIcon::Trigger);
private:
virtual QIcon getIcon() { return QIcon(); }
virtual QIcon getMainIcon(bool /*hasNew*/) { return QIcon(); }
virtual unsigned int getNewCount() { return 0; }
virtual QString getTrayMessage(bool plural);
virtual QString getNotifyMessage(bool plural);
virtual void iconClicked() {}
QAction *mMainIcon;
QSystemTrayIcon *mTrayIcon;
QAction *mNotifyIcon;
unsigned int newCount;
};
#endif // USERNOTIFY_H

View File

@ -0,0 +1,93 @@
/****************************************************************
* 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 "ForumUserNotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
#include <retroshare/rsforums.h>
ForumUserNotify::ForumUserNotify(QObject *parent) :
UserNotify(parent)
{
connect(NotifyQt::getInstance(), SIGNAL(forumsChanged()), this, SLOT(updateIcon()), Qt::QueuedConnection);
}
bool ForumUserNotify::hasSetting(QString &name)
{
name = tr("Forum Post");
return true;
}
bool ForumUserNotify::notifyEnabled()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_FORUMS);
}
bool ForumUserNotify::notifyCombined()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_FORUMS_COMBINED);
}
void ForumUserNotify::setNotifyEnabled(bool enabled, bool combined)
{
uint notifyFlags = Settings->getTrayNotifyFlags();
if (enabled) {
notifyFlags |= TRAYNOTIFY_FORUMS;
} else {
notifyFlags &= ~TRAYNOTIFY_FORUMS;
}
if (combined) {
notifyFlags |= TRAYNOTIFY_FORUMS_COMBINED;
} else {
notifyFlags &= ~TRAYNOTIFY_FORUMS_COMBINED;
}
Settings->setTrayNotifyFlags(notifyFlags);
}
QIcon ForumUserNotify::getIcon()
{
return QIcon(":/images/konversation16.png");
}
QIcon ForumUserNotify::getMainIcon(bool hasNew)
{
return hasNew ? QIcon(":/images/konversation_new.png") : QIcon(":/images/konversation.png");
}
unsigned int ForumUserNotify::getNewCount()
{
unsigned int newMessageCount = 0;
unsigned int unreadMessageCount = 0;
rsForums->getMessageCount("", newMessageCount, unreadMessageCount);
return newMessageCount;
}
void ForumUserNotify::iconClicked()
{
MainWindow::showWindow(MainWindow::Forums);
}

View File

@ -0,0 +1,46 @@
/****************************************************************
* 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 FORUMUSERNOTIFY_H
#define FORUMUSERNOTIFY_H
#include "gui/common/UserNotify.h"
class ForumUserNotify : public UserNotify
{
Q_OBJECT
public:
ForumUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString &name);
virtual bool notifyEnabled();
virtual bool notifyCombined();
virtual void setNotifyEnabled(bool enabled, bool combined);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);
virtual unsigned int getNewCount();
virtual void iconClicked();
};
#endif // FORUMUSERNOTIFY_H

View File

@ -0,0 +1,92 @@
/****************************************************************
* 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 "MessageUserNotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
#include <retroshare/rsmsgs.h>
MessageUserNotify::MessageUserNotify(QObject *parent) :
UserNotify(parent)
{
connect(NotifyQt::getInstance(), SIGNAL(messagesChanged()), this, SLOT(updateIcon()));
}
bool MessageUserNotify::hasSetting(QString &name)
{
name = tr("Message");
return true;
}
bool MessageUserNotify::notifyEnabled()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_MESSAGES);
}
bool MessageUserNotify::notifyCombined()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_MESSAGES_COMBINED);
}
void MessageUserNotify::setNotifyEnabled(bool enabled, bool combined)
{
uint notifyFlags = Settings->getTrayNotifyFlags();
if (enabled) {
notifyFlags |= TRAYNOTIFY_MESSAGES;
} else {
notifyFlags &= ~TRAYNOTIFY_MESSAGES;
}
if (combined) {
notifyFlags |= TRAYNOTIFY_MESSAGES_COMBINED;
} else {
notifyFlags &= ~TRAYNOTIFY_MESSAGES_COMBINED;
}
Settings->setTrayNotifyFlags(notifyFlags);
}
QIcon MessageUserNotify::getIcon()
{
return QIcon(":/images/newmsg.png");
}
QIcon MessageUserNotify::getMainIcon(bool hasNew)
{
return hasNew ? QIcon(":/images/messages_new.png") : QIcon(":/images/evolution.png");
}
unsigned int MessageUserNotify::getNewCount()
{
unsigned int newInboxCount = 0;
rsMsgs->getMessageCount(NULL, &newInboxCount, NULL, NULL, NULL, NULL);
return newInboxCount;
}
void MessageUserNotify::iconClicked()
{
MainWindow::showWindow(MainWindow::Messages);
}

View File

@ -0,0 +1,46 @@
/****************************************************************
* 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 MESSAGEUSERNOTIFY_H
#define MESSAGEUSERNOTIFY_H
#include "gui/common/UserNotify.h"
class MessageUserNotify : public UserNotify
{
Q_OBJECT
public:
MessageUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString &name);
virtual bool notifyEnabled();
virtual bool notifyCombined();
virtual void setNotifyEnabled(bool enabled, bool combined);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);
virtual unsigned int getNewCount();
virtual void iconClicked();
};
#endif // MESSAGEUSERNOTIFY_H

View File

@ -27,7 +27,7 @@
#include "rsharesettings.h"
#include "gui/MainWindow.h"
#include "gui/common/UserNotify.h"
/** Constructor */
NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
@ -36,11 +36,30 @@ NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
connect(ui.trayNotify_PrivateChat, SIGNAL(toggled(bool)), this, SLOT(privatChatToggled()));
connect(ui.trayNotify_Messages, SIGNAL(toggled(bool)), this, SLOT(privatChatToggled()));
connect(ui.trayNotify_Channels, SIGNAL(toggled(bool)), this, SLOT(privatChatToggled()));
connect(ui.trayNotify_Forums, SIGNAL(toggled(bool)), this, SLOT(privatChatToggled()));
connect(ui.trayNotify_Transfer, SIGNAL(toggled(bool)), this, SLOT(privatChatToggled()));
/* add user notify */
QFont font = ui.notify_Peers->font(); // use font from existing checkbox
const QList<UserNotify*> &userNotifyList = MainWindow::getInstance()->getUserNotifyList();
QList<UserNotify*>::const_iterator it;
int row = 0;
for (it = userNotifyList.begin(); it != userNotifyList.end(); ++it) {
UserNotify *userNotify = *it;
QString name;
if (!userNotify->hasSetting(name)) {
continue;
}
QCheckBox *enabledCheckBox = new QCheckBox(name, this);
enabledCheckBox->setFont(font);
ui.notifyLayout->addWidget(enabledCheckBox, row, 0, 0);
connect(enabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(notifyToggled()));
QCheckBox *combinedCheckBox = new QCheckBox(tr("Combined"), this);
combinedCheckBox->setFont(font);
ui.notifyLayout->addWidget(combinedCheckBox, row++, 1);
mUserNotifySettingList.push_back(UserNotifySetting(userNotify, enabledCheckBox, combinedCheckBox));
}
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -59,7 +78,6 @@ NotifyPage::save(QString &/*errmsg*/)
/* extract from rsNotify the flags */
uint notifyflags = 0;
uint traynotifyflags = 0;
uint newsflags = 0;
uint chatflags = 0;
uint messageflags = 0;
@ -103,33 +121,16 @@ NotifyPage::save(QString &/*errmsg*/)
if (ui.chat_tabbedWindow->isChecked())
chatflags |= RS_CHAT_TABBED_WINDOW;
if (ui.trayNotify_PrivateChat->isChecked())
traynotifyflags |= TRAYNOTIFY_PRIVATECHAT;
if (ui.trayNotify_Messages->isChecked())
traynotifyflags |= TRAYNOTIFY_MESSAGES;
if (ui.trayNotify_Channels->isChecked())
traynotifyflags |= TRAYNOTIFY_CHANNELS;
if (ui.trayNotify_Forums->isChecked())
traynotifyflags |= TRAYNOTIFY_FORUMS;
if (ui.trayNotify_Transfer->isChecked())
traynotifyflags |= TRAYNOTIFY_TRANSFERS;
if (ui.trayNotify_PrivateChatCombined->isChecked())
traynotifyflags |= TRAYNOTIFY_PRIVATECHAT_COMBINED;
if (ui.trayNotify_MessagesCombined->isChecked())
traynotifyflags |= TRAYNOTIFY_MESSAGES_COMBINED;
if (ui.trayNotify_ChannelsCombined->isChecked())
traynotifyflags |= TRAYNOTIFY_CHANNELS_COMBINED;
if (ui.trayNotify_ForumsCombined->isChecked())
traynotifyflags |= TRAYNOTIFY_FORUMS_COMBINED;
if (ui.trayNotify_TransferCombined->isChecked())
traynotifyflags |= TRAYNOTIFY_TRANSFERS_COMBINED;
if (ui.message_ConnectAttempt->isChecked())
messageflags |= RS_MESSAGE_CONNECT_ATTEMPT;
/* save user notify */
QList<UserNotifySetting>::iterator notifyIt;
for (notifyIt = mUserNotifySettingList.begin(); notifyIt != mUserNotifySettingList.end(); ++notifyIt) {
notifyIt->mUserNotify->setNotifyEnabled(notifyIt->mEnabledCheckBox->isChecked(), notifyIt->mCombinedCheckBox->isChecked());
}
Settings->setNotifyFlags(notifyflags);
Settings->setTrayNotifyFlags(traynotifyflags);
Settings->setNewsFeedFlags(newsflags);
Settings->setChatFlags(chatflags);
Settings->setMessageFlags(messageflags);
@ -152,13 +153,11 @@ NotifyPage::save(QString &/*errmsg*/)
return true;
}
/** Loads the settings for this page */
void NotifyPage::load()
{
/* extract from rsNotify the flags */
uint notifyflags = Settings->getNotifyFlags();
uint traynotifyflags = Settings->getTrayNotifyFlags();
uint newsflags = Settings->getNewsFeedFlags();
uint chatflags = Settings->getChatFlags();
uint messageflags = Settings->getMessageFlags();
@ -189,18 +188,6 @@ void NotifyPage::load()
ui.systray_GroupChat->setChecked(Settings->getDisplayTrayGroupChat());
ui.systray_ChatLobby->setChecked(Settings->getDisplayTrayChatLobby());
ui.trayNotify_PrivateChat->setChecked(traynotifyflags & TRAYNOTIFY_PRIVATECHAT);
ui.trayNotify_Messages->setChecked(traynotifyflags & TRAYNOTIFY_MESSAGES);
ui.trayNotify_Channels->setChecked(traynotifyflags & TRAYNOTIFY_CHANNELS);
ui.trayNotify_Forums->setChecked(traynotifyflags & TRAYNOTIFY_FORUMS);
ui.trayNotify_Transfer->setChecked(traynotifyflags & TRAYNOTIFY_TRANSFERS);
ui.trayNotify_PrivateChatCombined->setChecked(traynotifyflags & TRAYNOTIFY_PRIVATECHAT_COMBINED);
ui.trayNotify_MessagesCombined->setChecked(traynotifyflags & TRAYNOTIFY_MESSAGES_COMBINED);
ui.trayNotify_ChannelsCombined->setChecked(traynotifyflags & TRAYNOTIFY_CHANNELS_COMBINED);
ui.trayNotify_ForumsCombined->setChecked(traynotifyflags & TRAYNOTIFY_FORUMS_COMBINED);
ui.trayNotify_TransferCombined->setChecked(traynotifyflags & TRAYNOTIFY_TRANSFERS_COMBINED);
ui.addFeedsAtEnd->setChecked(Settings->getAddFeedsAtEnd());
RshareSettings::enumToasterPosition toasterPosition = Settings->getToasterPosition();
@ -226,25 +213,25 @@ void NotifyPage::load()
ui.spinBoxToasterXMargin->setValue(margin.x());
ui.spinBoxToasterYMargin->setValue(margin.y());
privatChatToggled();
/* load user notify */
QList<UserNotifySetting>::iterator notifyIt;
for (notifyIt = mUserNotifySettingList.begin(); notifyIt != mUserNotifySettingList.end(); ++notifyIt) {
notifyIt->mEnabledCheckBox->setChecked(notifyIt->mUserNotify->notifyEnabled());
notifyIt->mCombinedCheckBox->setChecked(notifyIt->mUserNotify->notifyCombined());
}
notifyToggled();
}
void NotifyPage::privatChatToggled()
void NotifyPage::notifyToggled()
{
QList<QPair<QCheckBox*, QCheckBox*> > checkboxes;
checkboxes << qMakePair(ui.trayNotify_PrivateChat, ui.trayNotify_PrivateChatCombined)
<< qMakePair(ui.trayNotify_Messages, ui.trayNotify_MessagesCombined)
<< qMakePair(ui.trayNotify_Channels, ui.trayNotify_ChannelsCombined)
<< qMakePair(ui.trayNotify_Forums, ui.trayNotify_ForumsCombined)
<< qMakePair(ui.trayNotify_Transfer, ui.trayNotify_TransferCombined);
QList<QPair<QCheckBox*, QCheckBox*> >::iterator checkboxIt;
for (checkboxIt = checkboxes.begin(); checkboxIt != checkboxes.end(); checkboxIt++) {
if (checkboxIt->first->isChecked()) {
checkboxIt->second->setEnabled(true);
QList<UserNotifySetting>::iterator notifyIt;
for (notifyIt = mUserNotifySettingList.begin(); notifyIt != mUserNotifySettingList.end(); ++notifyIt) {
if (notifyIt->mEnabledCheckBox->isChecked()) {
notifyIt->mCombinedCheckBox->setEnabled(true);
} else {
checkboxIt->second->setChecked(false);
checkboxIt->second->setEnabled(false);
notifyIt->mCombinedCheckBox->setChecked(false);
notifyIt->mCombinedCheckBox->setEnabled(false);
}
}
}

View File

@ -25,6 +25,20 @@
#include <retroshare-gui/configpage.h>
#include "ui_NotifyPage.h"
class UserNotify;
class UserNotifySetting
{
public:
UserNotify *mUserNotify;
QCheckBox *mEnabledCheckBox;
QCheckBox *mCombinedCheckBox;
public:
UserNotifySetting(UserNotify *userNotify, QCheckBox *enabledCheckBox, QCheckBox *combinedCheckBox)
: mUserNotify(userNotify), mEnabledCheckBox(enabledCheckBox), mCombinedCheckBox(combinedCheckBox) {}
};
class NotifyPage : public ConfigPage
{
Q_OBJECT
@ -44,9 +58,11 @@ public:
virtual QString pageName() const { return tr("Notify") ; }
private slots:
void privatChatToggled();
void notifyToggled();
private:
QList<UserNotifySetting> mUserNotifySettingList;
/** Qt Designer generated object */
Ui::NotifyPage ui;
};

View File

@ -587,78 +587,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="trayNotify_PrivateChat">
<property name="text">
<string>Private Chat</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="trayNotify_Messages">
<property name="text">
<string>Message</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="trayNotify_Channels">
<property name="text">
<string>Channel Post</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="trayNotify_Forums">
<property name="text">
<string>Forum Post</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="trayNotify_Transfer">
<property name="text">
<string>Download completed</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="trayNotify_PrivateChatCombined">
<property name="text">
<string>Combined</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="trayNotify_MessagesCombined">
<property name="text">
<string>Combined</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="trayNotify_ChannelsCombined">
<property name="text">
<string>Combined</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="trayNotify_ForumsCombined">
<property name="text">
<string>Combined</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="trayNotify_TransferCombined">
<property name="text">
<string>Combined</string>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" name="notifyLayout"/>
</item>
</layout>
</widget>

View File

@ -0,0 +1,105 @@
/****************************************************************
* 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 "TransferUserNotify.h"
#include "gui/settings/rsharesettings.h"
#include "gui/notifyqt.h"
#include "gui/MainWindow.h"
TransferUserNotify::TransferUserNotify(QObject *parent) :
UserNotify(parent)
{
newCount = 0;
connect(NotifyQt::getInstance(), SIGNAL(downloadCompleteCountChanged(int)), this, SLOT(downloadCountChanged(int)));
}
bool TransferUserNotify::hasSetting(QString &name)
{
name = tr("Download completed");
return true;
}
bool TransferUserNotify::notifyEnabled()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_TRANSFERS);
}
bool TransferUserNotify::notifyCombined()
{
return (Settings->getTrayNotifyFlags() & TRAYNOTIFY_TRANSFERS_COMBINED);
}
void TransferUserNotify::setNotifyEnabled(bool enabled, bool combined)
{
uint notifyFlags = Settings->getTrayNotifyFlags();
if (enabled) {
notifyFlags |= TRAYNOTIFY_TRANSFERS;
} else {
notifyFlags &= ~TRAYNOTIFY_TRANSFERS;
}
if (combined) {
notifyFlags |= TRAYNOTIFY_TRANSFERS_COMBINED;
} else {
notifyFlags &= ~TRAYNOTIFY_TRANSFERS_COMBINED;
}
Settings->setTrayNotifyFlags(notifyFlags);
}
QIcon TransferUserNotify::getIcon()
{
return QIcon(":/images/ktorrent32.png");
}
QIcon TransferUserNotify::getMainIcon(bool hasNew)
{
return hasNew ? QIcon(":/images/transfers_new32.png") : QIcon(":/images/ktorrent32.png");
}
unsigned int TransferUserNotify::getNewCount()
{
return newCount;
}
QString TransferUserNotify::getTrayMessage(bool plural)
{
return plural ? tr("You have %1 completed downloads") : tr("You have %1 completed download");
}
QString TransferUserNotify::getNotifyMessage(bool plural)
{
return plural ? tr("%1 completed downloads") : tr("%1 completed download");
}
void TransferUserNotify::iconClicked()
{
MainWindow::showWindow(MainWindow::Transfers);
}
void TransferUserNotify::downloadCountChanged(int count)
{
newCount = count;
updateIcon();
}

View File

@ -0,0 +1,53 @@
/****************************************************************
* 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 TRANSFERUSERNOTIFY_H
#define TRANSFERUSERNOTIFY_H
#include "gui/common/UserNotify.h"
class TransferUserNotify : public UserNotify
{
Q_OBJECT
public:
TransferUserNotify(QObject *parent = 0);
virtual bool hasSetting(QString &name);
virtual bool notifyEnabled();
virtual bool notifyCombined();
virtual void setNotifyEnabled(bool enabled, bool combined);
private slots:
void downloadCountChanged(int count);
private:
virtual QIcon getIcon();
virtual QIcon getMainIcon(bool hasNew);
virtual unsigned int getNewCount();
virtual QString getTrayMessage(bool plural);
virtual QString getNotifyMessage(bool plural);
virtual void iconClicked();
int newCount;
};
#endif // TRANSFERUSERNOTIFY_H

View File

@ -360,14 +360,9 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ;
QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) ));
QObject::connect(notify,SIGNAL(privateChatChanged(int, int)) ,w ,SLOT(privateChatChanged(int, int) ));
QObject::connect(notify,SIGNAL(neighboursChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ;
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
QObject::connect(notify,SIGNAL(messagesTagsChanged()) ,w->messagesDialog ,SLOT(messagesTagsChanged() )) ;
QObject::connect(notify,SIGNAL(messagesChanged()) ,w ,SLOT(updateMessages() )) ;
QObject::connect(notify,SIGNAL(forumsChanged()) ,w ,SLOT(updateForums() ), Qt::QueuedConnection);
QObject::connect(notify,SIGNAL(channelsChanged(int)) ,w ,SLOT(updateChannels(int) ), Qt::QueuedConnection);
QObject::connect(notify,SIGNAL(downloadCompleteCountChanged(int)) ,w ,SLOT(updateTransfers(int) ));
QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->friendsDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool)));
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->friendsDialog,SLOT(loadmypersonalstatus()));

View File

@ -244,6 +244,7 @@ HEADERS += rshare.h \
gui/forums/EditForumDetails.h \
gui/forums/CreateForum.h \
gui/forums/CreateForumMsg.h \
gui/forums/ForumUserNotify.h \
gui/NetworkView.h \
gui/TrustView.h \
gui/MessengerWindow.h \
@ -302,11 +303,13 @@ HEADERS += rshare.h \
gui/chat/ChatLobbyDialog.h \
gui/chat/CreateLobbyDialog.h \
gui/chat/ChatStyle.h \
gui/chat/ChatUserNotify.h \
gui/channels/CreateChannel.h \
gui/channels/ChannelDetails.h \
gui/channels/CreateChannelMsg.h \
gui/channels/EditChanDetails.h \
gui/channels/ShareKey.h \
gui/channels/ChannelUserNotify.h \
gui/connect/ConfCertDialog.h \
gui/connect/FriendRequest.h \
gui/msgs/MessageComposer.h \
@ -314,6 +317,8 @@ HEADERS += rshare.h \
gui/msgs/MessageWidget.h \
gui/msgs/TagsMenu.h \
gui/msgs/textformat.h \
gui/msgs/MessageUserNotify.h \
gui/transfers/TransferUserNotify.h \
gui/images/retroshare_win.rc.h \
gui/settings/rsharesettings.h \
gui/settings/RsharePeerSettings.h \
@ -371,6 +376,7 @@ HEADERS += rshare.h \
gui/common/LineEditClear.h \
gui/common/DropLineEdit.h \
gui/common/LinkTextBrowser.h \
gui/common/UserNotify.h \
gui/style/RSStyle.h \
gui/style/StyleDialog.h \
gui/MessagesDialog.h \
@ -534,6 +540,7 @@ SOURCES += main.cpp \
gui/forums/EditForumDetails.cpp \
gui/forums/CreateForum.cpp \
gui/forums/CreateForumMsg.cpp \
gui/forums/ForumUserNotify.cpp \
gui/NetworkView.cpp \
gui/TrustView.cpp \
gui/MessengerWindow.cpp \
@ -586,6 +593,7 @@ SOURCES += main.cpp \
gui/channels/ChannelDetails.cpp \
gui/channels/EditChanDetails.cpp \
gui/channels/ShareKey.cpp \
gui/channels/ChannelUserNotify.cpp \
gui/chat/PopupChatWindow.cpp \
gui/chat/PopupChatDialog.cpp \
gui/chat/ChatTabWidget.cpp \
@ -595,12 +603,15 @@ SOURCES += main.cpp \
gui/chat/ChatLobbyDialog.cpp \
gui/chat/CreateLobbyDialog.cpp \
gui/chat/ChatStyle.cpp \
gui/chat/ChatUserNotify.cpp \
gui/connect/ConfCertDialog.cpp \
gui/connect/FriendRequest.cpp \
gui/msgs/MessageComposer.cpp \
gui/msgs/MessageWidget.cpp \
gui/msgs/MessageWindow.cpp \
gui/msgs/TagsMenu.cpp \
gui/msgs/MessageUserNotify.cpp \
gui/transfers/TransferUserNotify.cpp \
gui/common/vmessagebox.cpp \
gui/common/RsCollectionFile.cpp \
gui/common/RsCollectionDialog.cpp \
@ -628,6 +639,7 @@ SOURCES += main.cpp \
gui/common/LineEditClear.cpp \
gui/common/DropLineEdit.cpp \
gui/common/LinkTextBrowser.cpp \
gui/common/UserNotify.cpp \
gui/style/RSStyle.cpp \
gui/style/StyleDialog.cpp \
gui/settings/rsharesettings.cpp \

View File

@ -25,6 +25,7 @@
#include <QWidget>
class UserNotify;
class MainPage : public QWidget
{
@ -33,6 +34,7 @@ public:
MainPage(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {}
virtual void retranslateUi() {}
virtual UserNotify *getUserNotify(QObject */*parent*/) { return NULL; }
};
#endif