linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04184
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2542: clicking a balloon activates the relevant tab
------------------------------------------------------------
revno: 2542
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2011-05-29 23:40:28 +0200
message:
clicking a balloon activates the relevant tab
modified:
dwt/include/dwt/widgets/Notification.h
dwt/src/widgets/Notification.cpp
win32/DirectoryListingFrame.cpp
win32/DirectoryListingFrame.h
win32/HubFrame.cpp
win32/HubFrame.h
win32/MainWindow.cpp
win32/MainWindow.h
win32/PrivateFrame.cpp
win32/PrivateFrame.h
win32/WinUtil.cpp
win32/WinUtil.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/widgets/Notification.h'
--- dwt/include/dwt/widgets/Notification.h 2011-05-27 11:00:40 +0000
+++ dwt/include/dwt/widgets/Notification.h 2011-05-29 21:40:28 +0000
@@ -34,6 +34,8 @@
#include "../resources/Icon.h"
#include "Window.h"
+#include <deque>
+
namespace dwt {
/** A notification object represents a tray icon and a short message notification service */
@@ -58,21 +60,18 @@
void setTooltip(const tstring& tip);
+ typedef std::function<void ()> Callback;
+
/** show a balloon popup.
+ @param callback callback called when the balloon has been clicked.
@param balloonIcon icon shown next to the title, only available on >= Vista. */
- void addMessage(const tstring& title, const tstring& message, const IconPtr& balloonIcon = 0);
-
- // TODO Fix callback parameters
- typedef std::function<void ()> Callback;
+ void addMessage(const tstring& title, const tstring& message, const Callback& callback, const IconPtr& balloonIcon = 0);
void onContextMenu(const Callback& callback_) { contextMenu = callback_; }
/// The icon was left-clicked / selected
void onIconClicked(const Callback& callback_) { iconClicked = callback_; }
- /// The message added by addMessage was clicked
- void onBalloonClicked(const Callback& callback_) { balloonClicked = callback_; }
-
/// This is sent when the tooltip text should be updated
void onUpdateTip(const Callback& callback_) { updateTip = callback_; }
@@ -81,17 +80,16 @@
IconPtr icon;
bool visible;
- size_t balloons; /// amount of queued balloons (to know when to disable a message-only icon).
tstring tip;
- /** List of messages to display */
- std::list<tstring> messages;
Callback contextMenu;
Callback iconClicked;
- Callback balloonClicked;
Callback updateTip;
+ std::deque<Callback> balloons;
+ bool onlyBalloons; /// the icon has been created solely for balloons; it will disappear afterwards.
+
NOTIFYICONDATA makeNID() const;
/// Last tick that tip was updated
=== modified file 'dwt/src/widgets/Notification.cpp'
--- dwt/src/widgets/Notification.cpp 2011-05-27 11:22:59 +0000
+++ dwt/src/widgets/Notification.cpp 2011-05-29 21:40:28 +0000
@@ -63,7 +63,7 @@
Notification::Notification(WindowPtr parent_) :
parent(parent_),
visible(false),
-balloons(0),
+onlyBalloons(false),
lastTick(0)
{
}
@@ -88,8 +88,8 @@
void Notification::setVisible(bool visible_) {
if(visible == visible_) {
- if(visible && balloons)
- balloons = 0;
+ if(visible && onlyBalloons)
+ onlyBalloons = false;
return;
}
@@ -130,11 +130,13 @@
}
}
-void Notification::addMessage(const tstring& title, const tstring& message, const IconPtr& balloonIcon) {
- if(!visible || balloons)
- ++balloons;
- if(!visible)
+void Notification::addMessage(const tstring& title, const tstring& message, const Callback& callback, const IconPtr& balloonIcon) {
+ if(!visible) {
setVisible(true);
+ onlyBalloons = true;
+ }
+
+ balloons.push_back(callback);
NOTIFYICONDATA nid = makeNID();
nid.uFlags |= NIF_INFO;
@@ -162,7 +164,8 @@
}
bool Notification::trayHandler(const MSG& msg) {
- switch(msg.lParam) {
+ switch(LOWORD(msg.lParam)) {
+
case WM_LBUTTONUP:
{
if(iconClicked) {
@@ -196,14 +199,13 @@
case NIN_BALLOONUSERCLICK:
{
- if(balloonClicked) {
- balloonClicked();
- }
+ balloons.front()();
} // fall through
case NIN_BALLOONHIDE: // fall through
case NIN_BALLOONTIMEOUT:
{
- if(balloons && !--balloons) {
+ balloons.pop_front();
+ if(onlyBalloons && balloons.empty()) {
setVisible(false);
}
break;
=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp 2011-05-04 19:32:00 +0000
+++ win32/DirectoryListingFrame.cpp 2011-05-29 21:40:28 +0000
@@ -201,6 +201,13 @@
}
}
+void DirectoryListingFrame::activateWindow(const HintedUser& aUser) {
+ auto i = lists.find(aUser);
+ if(i != lists.end()) {
+ i->second->activate();
+ }
+}
+
DirectoryListingFrame::DirectoryListingFrame(TabViewPtr parent, const HintedUser& aUser, int64_t aSpeed) :
BaseType(parent, _T(""), IDH_FILE_LIST, IDI_DIRECTORY, false),
rebar(0),
=== modified file 'win32/DirectoryListingFrame.h'
--- win32/DirectoryListingFrame.h 2011-05-04 19:32:00 +0000
+++ win32/DirectoryListingFrame.h 2011-05-29 21:40:28 +0000
@@ -69,6 +69,7 @@
static void openWindow_(TabViewPtr parent, const tstring& aFile, const tstring& aDir, const HintedUser& aUser, int64_t aSpeed, Activation activate);
public:
static void openWindow(TabViewPtr parent, const HintedUser& aUser, const string& txt, int64_t aSpeed);
+ static void activateWindow(const HintedUser& aUser);
static void openOwnList(TabViewPtr parent, const tstring& dir = Util::emptyStringT, Activation activate = FOLLOW_SETTING);
static void closeAll();
=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp 2011-05-27 11:03:29 +0000
+++ win32/HubFrame.cpp 2011-05-29 21:40:28 +0000
@@ -82,6 +82,15 @@
frame->activate();
}
+void HubFrame::activateWindow(const string& url) {
+ for(auto i = frames.cbegin(), iend = frames.cend(); i != iend; ++i) {
+ auto frame = *i;
+ if(frame->url == url) {
+ frame->activate();
+ }
+ }
+}
+
void HubFrame::closeAll(bool all) {
for(FrameIter i = frames.begin(); i != frames.end(); ++i) {
HubFrame* frame = *i;
@@ -463,7 +472,10 @@
void HubFrame::addChat(const tstring& aLine) {
ChatType::addChat(client, aLine);
- WinUtil::notify(WinUtil::NOTIFICATION_MAIN_CHAT, aLine);
+ {
+ auto u = url;
+ WinUtil::notify(WinUtil::NOTIFICATION_MAIN_CHAT, aLine, [u] { activateWindow(u); });
+ }
setDirty(SettingsManager::BOLD_HUB);
if(BOOLSETTING(LOG_MAIN_CHAT)) {
=== modified file 'win32/HubFrame.h'
--- win32/HubFrame.h 2011-05-06 22:46:06 +0000
+++ win32/HubFrame.h 2011-05-29 21:40:28 +0000
@@ -66,6 +66,7 @@
const string& getId() const;
static void openWindow(TabViewPtr parent, const string& url, bool activate = true, bool connect = true);
+ static void activateWindow(const string& url);
static void closeAll(bool all);
static void closeFavGroup(const string& group, bool reversed);
static void resortUsers();
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-05-27 17:44:05 +0000
+++ win32/MainWindow.cpp 2011-05-29 21:40:28 +0000
@@ -558,7 +558,6 @@
notifier->onContextMenu([this] { handleTrayContextMenu(); });
notifier->onIconClicked([this] { handleTrayClicked(); });
notifier->onUpdateTip([this] { handleTrayUpdate(); });
- notifier->onBalloonClicked([this] { handleRestore(); });
if(SETTING(ALWAYS_TRAY)) {
notifier->setVisible(true);
}
@@ -585,8 +584,8 @@
return false;
}
-void MainWindow::notify(const tstring& title, const tstring& message, const dwt::IconPtr& balloonIcon) {
- notifier->addMessage(_T("DC++ - ") + title, message, balloonIcon);
+void MainWindow::notify(const tstring& title, const tstring& message, const std::function<void ()>& callback, const dwt::IconPtr& balloonIcon) {
+ notifier->addMessage(str(TF_("DC++ - %1%") % title), message, [this, callback] { handleRestore(); if(callback) callback(); }, balloonIcon);
}
void MainWindow::setStaticWindowState(const string& id, bool open) {
@@ -1512,7 +1511,8 @@
auto user = qi->getDownloads()[0]->getHintedUser();
callAsync([this, file, dir, user, speed] {
DirectoryListingFrame::openWindow(getTabView(), Text::toT(file), Text::toT(dir), user, speed);
- WinUtil::notify(WinUtil::NOTIFICATION_FINISHED_FL, Text::toT(Util::getFileName(file)));
+ WinUtil::notify(WinUtil::NOTIFICATION_FINISHED_FL, Text::toT(Util::getFileName(file)),
+ [=] { DirectoryListingFrame::activateWindow(user); });
});
} else if(qi->isSet(QueueItem::FLAG_TEXT)) {
@@ -1526,8 +1526,11 @@
if(!qi->isSet(QueueItem::FLAG_USER_LIST)) {
auto file = qi->getTarget();
- callAsync([file] {
- WinUtil::notify(WinUtil::NOTIFICATION_FINISHED_DL, Text::toT(file));
+ callAsync([this, file] {
+ WinUtil::notify(WinUtil::NOTIFICATION_FINISHED_DL, Text::toT(file), [=] {
+ FinishedDLFrame::openWindow(getTabView(), false);
+ ///@todo focus the file in the finished download list?
+ });
});
}
}
=== modified file 'win32/MainWindow.h'
--- win32/MainWindow.h 2011-05-27 17:44:05 +0000
+++ win32/MainWindow.h 2011-05-29 21:40:28 +0000
@@ -64,7 +64,8 @@
void handleSettings();
- void notify(const tstring& title, const tstring& message, const dwt::IconPtr& balloonIcon = 0);
+ /** show a balloon popup. refer to the dwt::Notification::addMessage doc for info about parameters. */
+ void notify(const tstring& title, const tstring& message, const std::function<void ()>& callback = 0, const dwt::IconPtr& balloonIcon = 0);
void setStaticWindowState(const string& id, bool open);
void TrayPM();
=== modified file 'win32/PrivateFrame.cpp'
--- win32/PrivateFrame.cpp 2011-05-27 11:03:29 +0000
+++ win32/PrivateFrame.cpp 2011-05-29 21:40:28 +0000
@@ -69,13 +69,19 @@
if(!(BOOLSETTING(NO_AWAYMSG_TO_BOTS) && user->isSet(User::BOT)))
p->sendMessage(Text::toT(Util::getAwayMessage()));
}
- WinUtil::notify(WinUtil::NOTIFICATION_PM_WINDOW, aMessage);
+ WinUtil::notify(WinUtil::NOTIFICATION_PM_WINDOW, aMessage, [user] { activateWindow(user); });
} else {
i->second->addChat(aMessage);
- WinUtil::notify(WinUtil::NOTIFICATION_PM, aMessage);
+ WinUtil::notify(WinUtil::NOTIFICATION_PM, aMessage, [user] { activateWindow(user); });
}
}
+void PrivateFrame::activateWindow(const UserPtr& u) {
+ auto i = frames.find(u);
+ if(i != frames.end())
+ i->second->activate();
+}
+
void PrivateFrame::closeAll(){
for(FrameIter i = frames.begin(); i != frames.end(); ++i)
i->second->close(true);
=== modified file 'win32/PrivateFrame.h'
--- win32/PrivateFrame.h 2011-05-04 19:32:00 +0000
+++ win32/PrivateFrame.h 2011-05-29 21:40:28 +0000
@@ -59,6 +59,7 @@
const tstring& aMessage, const string& hubHint);
static void openWindow(TabViewPtr parent, const HintedUser& replyTo, const tstring& msg = Util::emptyStringT,
const string& logPath = Util::emptyString, bool activate = true);
+ static void activateWindow(const UserPtr& u);
static bool isOpen(const UserPtr& u) { return frames.find(u) != frames.end(); }
static void closeAll();
static void closeAllOffline();
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-05-28 15:12:11 +0000
+++ win32/WinUtil.cpp 2011-05-29 21:40:28 +0000
@@ -556,7 +556,7 @@
return true;
}
-void WinUtil::notify(NotificationType notification, const tstring& balloonText) {
+void WinUtil::notify(NotificationType notification, const tstring& balloonText, const std::function<void ()>& balloonCallback) {
const auto& n = notifications[notification];
const string& s = SettingsManager::getInstance()->get((SettingsManager::StrSetting)n.sound);
@@ -566,7 +566,7 @@
int b = SettingsManager::getInstance()->get((SettingsManager::IntSetting)n.balloon);
if(b == SettingsManager::BALLOON_ALWAYS || (b == SettingsManager::BALLOON_BACKGROUND && !mainWindow->onForeground())) {
- mainWindow->notify(T_(n.title), balloonText, createIcon(n.icon, 16));
+ mainWindow->notify(T_(n.title), balloonText, balloonCallback, createIcon(n.icon, 16));
}
}
=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h 2011-05-27 11:03:29 +0000
+++ win32/WinUtil.h 2011-05-29 21:40:28 +0000
@@ -181,7 +181,7 @@
*/
static bool checkCommand(tstring& cmd, tstring& param, tstring& message, tstring& status, bool& thirdPerson);
- static void notify(NotificationType notification, const tstring& balloonText);
+ static void notify(NotificationType notification, const tstring& balloonText, const std::function<void ()>& balloonCallback = 0);
static void playSound(const tstring& sound);
static void openFile(const tstring& file);