linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04047
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2514: add a setting to show balloons only when DC++ is in the background
------------------------------------------------------------
revno: 2514
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2011-04-25 23:52:03 +0200
message:
add a setting to show balloons only when DC++ is in the background
modified:
dcpp/SettingsManager.cpp
dcpp/SettingsManager.h
dwt/include/dwt/widgets/Window.h
dwt/src/widgets/Window.cpp
help/settings_notifications.html
win32/MainWindow.cpp
win32/NotificationsPage.cpp
win32/NotificationsPage.h
win32/WinUtil.cpp
--
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 'dcpp/SettingsManager.cpp'
--- dcpp/SettingsManager.cpp 2011-04-23 10:33:55 +0000
+++ dcpp/SettingsManager.cpp 2011-04-25 21:52:03 +0000
@@ -314,11 +314,11 @@
setDefault(SLOTS_ALTERNATE_LIMITING, 1);
setDefault(SLOTS_PRIMARY, 3);
setDefault(SETTINGS_SAVE_INTERVAL, 10);
- setDefault(BALLOON_MAIN_CHAT, false);
- setDefault(BALLOON_PM, false);
- setDefault(BALLOON_PM_WINDOW, false);
- setDefault(BALLOON_FINISHED_DL, true);
- setDefault(BALLOON_FINISHED_FL, false);
+ setDefault(BALLOON_MAIN_CHAT, BALLOON_DISABLED);
+ setDefault(BALLOON_PM, BALLOON_DISABLED);
+ setDefault(BALLOON_PM_WINDOW, BALLOON_DISABLED);
+ setDefault(BALLOON_FINISHED_DL, BALLOON_ALWAYS);
+ setDefault(BALLOON_FINISHED_FL, BALLOON_DISABLED);
setSearchTypeDefaults();
=== modified file 'dcpp/SettingsManager.h'
--- dcpp/SettingsManager.h 2011-04-23 10:33:55 +0000
+++ dcpp/SettingsManager.h 2011-04-25 21:52:03 +0000
@@ -134,6 +134,8 @@
enum { MAGNET_AUTO_SEARCH, MAGNET_AUTO_DOWNLOAD };
+ enum { BALLOON_DISABLED, BALLOON_ALWAYS, BALLOON_BACKGROUND };
+
const string& get(StrSetting key, bool useDefault = true) const {
return (isSet[key] || !useDefault) ? strSettings[key - STR_FIRST] : strDefaults[key - STR_FIRST];
}
=== modified file 'dwt/include/dwt/widgets/Window.h'
--- dwt/include/dwt/widgets/Window.h 2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/Window.h 2011-04-25 21:52:03 +0000
@@ -88,6 +88,9 @@
explicit Window(Widget* parent = 0, Dispatcher& dispatcher = NormalDispatcher::getDefault());
virtual ~Window();
+
+ /// @return whether this window (or a dialog it owns) is the current foreground window.
+ bool onForeground() const;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
=== modified file 'dwt/src/widgets/Window.cpp'
--- dwt/src/widgets/Window.cpp 2011-01-02 17:12:02 +0000
+++ dwt/src/widgets/Window.cpp 2011-04-25 21:52:03 +0000
@@ -40,4 +40,8 @@
BaseType::create(cs);
}
+bool Window::onForeground() const {
+ return ::GetAncestor(::GetForegroundWindow(), GA_ROOTOWNER) == handle();
+}
+
}
=== modified file 'help/settings_notifications.html'
--- help/settings_notifications.html 2011-04-23 10:33:55 +0000
+++ help/settings_notifications.html 2011-04-25 21:52:03 +0000
@@ -58,13 +58,21 @@
desired event.
</p>
- <h2>Notification sound</h2>
- <p cshelp="IDH_SETTINGS_NOTIFICATIONS_BEEPFILE">
+ <h2>Sound settings</h2>
+ <p cshelp="IDH_SETTINGS_NOTIFICATIONS_SOUND_FILE">
Instead of the system's default beep, a custom sound can be assigned to each event by selecting
the desired event in the "Notifications" list, enabling the "Sound" icon, then clicking the
"Browse..." button. Only Wave sound files (typically with a ".wav" extension) are allowed.
</p>
+ <h2>Balloon settings</h2>
+ <h3>Display the balloon only when DC++ is in the background</h3>
+ <p cshelp="IDH_SETTINGS_NOTIFICATIONS_BALLOON_BG">
+ When this box is checked, balloons popups will fire to signal the selected event only when DC++
+ is in the background (either minimized or not the active window). Otherwise, they will always
+ be displayed whenever the selected event is signalled.
+ </p>
+
<h2>Fire a balloon popup example</h2>
<p cshelp="IDH_SETTINGS_NOTIFICATIONS_BALLOON_EXAMPLE">
Pressing this button will have DC++ launch a balloon popup example from the Windows
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-04-24 19:53:20 +0000
+++ win32/MainWindow.cpp 2011-04-25 21:52:03 +0000
@@ -577,7 +577,7 @@
}
void MainWindow::TrayPM() {
- if(!tray_pm && notifier->isVisible() && ::GetAncestor(::GetForegroundWindow(), GA_ROOTOWNER) != handle()) {
+ if(!tray_pm && notifier->isVisible() && !onForeground()) {
notifier->setIcon(WinUtil::createIcon(IDI_TRAY_PM, 16));
tray_pm = true;
}
=== modified file 'win32/NotificationsPage.cpp'
--- win32/NotificationsPage.cpp 2011-04-23 10:33:55 +0000
+++ win32/NotificationsPage.cpp 2011-04-25 21:52:03 +0000
@@ -30,15 +30,15 @@
NotificationsPage::Option NotificationsPage::options[] = {
{ N_("Download finished"), SettingsManager::SOUND_FINISHED_DL, Util::emptyStringT,
- SettingsManager::BALLOON_FINISHED_DL, false, IDH_SETTINGS_NOTIFICATIONS_FINISHED_DL },
+ SettingsManager::BALLOON_FINISHED_DL, 0, IDH_SETTINGS_NOTIFICATIONS_FINISHED_DL },
{ N_("File list downloaded"), SettingsManager::SOUND_FINISHED_FL, Util::emptyStringT,
- SettingsManager::BALLOON_FINISHED_FL, false, IDH_SETTINGS_NOTIFICATIONS_FINISHED_FL },
+ SettingsManager::BALLOON_FINISHED_FL, 0, IDH_SETTINGS_NOTIFICATIONS_FINISHED_FL },
{ N_("Main chat message received"), SettingsManager::SOUND_MAIN_CHAT, Util::emptyStringT,
- SettingsManager::BALLOON_MAIN_CHAT, false, IDH_SETTINGS_NOTIFICATIONS_MAIN_CHAT },
+ SettingsManager::BALLOON_MAIN_CHAT, 0, IDH_SETTINGS_NOTIFICATIONS_MAIN_CHAT },
{ N_("Private message received"), SettingsManager::SOUND_PM, Util::emptyStringT,
- SettingsManager::BALLOON_PM, false, IDH_SETTINGS_NOTIFICATIONS_PM },
+ SettingsManager::BALLOON_PM, 0, IDH_SETTINGS_NOTIFICATIONS_PM },
{ N_("Private message window opened"), SettingsManager::SOUND_PM_WINDOW, Util::emptyStringT,
- SettingsManager::BALLOON_PM_WINDOW, false, IDH_SETTINGS_NOTIFICATIONS_PM_WINDOW }
+ SettingsManager::BALLOON_PM_WINDOW, 0, IDH_SETTINGS_NOTIFICATIONS_PM_WINDOW }
};
static const ColumnInfo columns[] = {
@@ -49,13 +49,14 @@
};
NotificationsPage::NotificationsPage(dwt::Widget* parent) :
-PropPage(parent, 5, 1),
+PropPage(parent, 6, 1),
table(0),
sound(0),
balloon(0),
-beepGroup(0),
-beepFile(0),
-prevSelection(-1)
+soundGroup(0),
+soundFile(0),
+balloonGroup(0),
+balloonBg(0)
{
setHelpId(IDH_NOTIFICATIONSPAGE);
@@ -98,22 +99,31 @@
}
{
- beepGroup = grid->addChild(GroupBox::Seed(T_("Notification sound")));
- beepGroup->setHelpId(IDH_SETTINGS_NOTIFICATIONS_BEEPFILE);
+ soundGroup = grid->addChild(GroupBox::Seed(T_("Sound settings")));
+ soundGroup->setHelpId(IDH_SETTINGS_NOTIFICATIONS_SOUND_FILE);
- auto cur = beepGroup->addChild(Grid::Seed(1, 3));
+ auto cur = soundGroup->addChild(Grid::Seed(1, 3));
cur->column(1).mode = GridInfo::FILL;
auto button = cur->addChild(Button::Seed(T_("Play")));
button->setImage(WinUtil::buttonIcon(IDI_SOUND));
button->onClicked([this] { handlePlayClicked(); });
- beepFile = cur->addChild(WinUtil::Seeds::Dialog::textBox);
+ soundFile = cur->addChild(WinUtil::Seeds::Dialog::textBox);
+ soundFile->onUpdated([this] { handleSoundChanged(); });
cur->addChild(Button::Seed(T_("&Browse...")))->onClicked([this] { handleBrowseClicked(); });
}
{
+ balloonGroup = grid->addChild(GroupBox::Seed(T_("Balloon settings")));
+
+ balloonBg = balloonGroup->addChild(CheckBox::Seed(T_("Display the balloon only when DC++ is in the background")));
+ balloonBg->setHelpId(IDH_SETTINGS_NOTIFICATIONS_BALLOON_BG);
+ balloonBg->onClicked([this] { handleBalloonBgClicked(); });
+ }
+
+ {
auto button = grid->addChild(Grid::Seed(1, 1))->addChild(Button::Seed(T_("Fire a balloon popup example")));
button->setHelpId(IDH_SETTINGS_NOTIFICATIONS_BALLOON_EXAMPLE);
button->setImage(WinUtil::buttonIcon(IDI_BALLOON));
@@ -124,14 +134,14 @@
for(size_t i = 0, n = sizeof(options) / sizeof(Option); i < n; ++i) {
options[i].sound = Text::toT(SettingsManager::getInstance()->get((SettingsManager::StrSetting)options[i].soundSetting));
- options[i].balloon = SettingsManager::getInstance()->getBool((SettingsManager::IntSetting)options[i].balloonSetting);
+ options[i].balloon = SettingsManager::getInstance()->get((SettingsManager::IntSetting)options[i].balloonSetting);
TStringList row(COLUMN_LAST);
row[COLUMN_TEXT] = T_(options[i].text);
table->insert(row);
- update(i, COLUMN_SOUND, !options[i].sound.empty());
- update(i, COLUMN_BALLOON, options[i].balloon);
+ updateSound(i);
+ updateBalloon(i);
}
handleSelectionChanged();
@@ -153,8 +163,6 @@
}
void NotificationsPage::write() {
- table->clearSelection(); // to save the current sound file
-
SettingsManager* settings = SettingsManager::getInstance();
for(size_t i = 0, n = sizeof(options) / sizeof(Option); i < n; ++i) {
settings->set((SettingsManager::StrSetting)options[i].soundSetting, Text::fromT(options[i].sound));
@@ -180,17 +188,15 @@
}
void NotificationsPage::handleSelectionChanged() {
- if(prevSelection >= 0) {
- auto& s = options[prevSelection].sound;
- if(s == _T("beep") && beepFile->length() > 0)
- s = beepFile->getText();
- }
-
int sel = table->getSelected();
if(sel >= 0) {
auto& s = options[sel].sound;
- beepGroup->setEnabled(!s.empty());
- beepFile->setText((s == _T("beep")) ? Util::emptyStringT : s);
+ soundGroup->setEnabled(!s.empty());
+ soundFile->setText((s == _T("beep")) ? Util::emptyStringT : s);
+
+ auto& b = options[sel].balloon;
+ balloonGroup->setEnabled(b != SettingsManager::BALLOON_DISABLED);
+ balloonBg->setChecked(b == SettingsManager::BALLOON_BACKGROUND);
sound->setChecked(!s.empty());
sound->setEnabled(true);
@@ -199,8 +205,11 @@
balloon->setEnabled(true);
} else {
- beepGroup->setEnabled(false);
- beepFile->setText(Util::emptyStringT);
+ soundGroup->setEnabled(false);
+ soundFile->setText(Util::emptyStringT);
+
+ balloonGroup->setEnabled(false);
+ balloonBg->setChecked(false);
sound->setChecked(false);
sound->setEnabled(false);
@@ -208,8 +217,6 @@
balloon->setChecked(false);
balloon->setEnabled(false);
}
-
- prevSelection = sel;
}
void NotificationsPage::handleDblClicked() {
@@ -232,7 +239,7 @@
s = _T("beep");
else
s.clear();
- update(sel, COLUMN_SOUND, !s.empty());
+ updateSound(sel);
handleSelectionChanged();
}
}
@@ -241,29 +248,55 @@
auto sel = table->getSelected();
if(sel >= 0) {
auto& b = options[sel].balloon;
- b = !b;
- update(sel, COLUMN_BALLOON, b);
+ b = (b == SettingsManager::BALLOON_DISABLED) ? SettingsManager::BALLOON_ALWAYS : SettingsManager::BALLOON_DISABLED;
+ updateBalloon(sel);
handleSelectionChanged();
}
}
void NotificationsPage::handlePlayClicked() {
- auto s = beepFile->getText();
- WinUtil::playSound(s.empty() ? _T("beep") : s);
+ WinUtil::playSound(options[table->getSelected()].sound);
+}
+
+void NotificationsPage::handleSoundChanged() {
+ if(!soundFile->getEnabled())
+ return;
+
+ auto sel = table->getSelected();
+ auto& s = options[sel].sound;
+ s = soundFile->getText();
+ if(s.empty())
+ s = _T("beep");
+ updateSound(sel);
}
void NotificationsPage::handleBrowseClicked() {
- tstring x = beepFile->getText();
+ tstring x = soundFile->getText();
if(LoadDialog(this).open(x)) {
- beepFile->setText(x);
+ soundFile->setText(x);
}
}
+void NotificationsPage::handleBalloonBgClicked() {
+ auto sel = table->getSelected();
+ auto& b = options[sel].balloon;
+ b = balloonBg->getChecked() ? SettingsManager::BALLOON_BACKGROUND : SettingsManager::BALLOON_ALWAYS;
+ updateBalloon(sel);
+}
+
void NotificationsPage::handleExampleClicked() {
WinUtil::mainWindow->notify(T_("Balloon popup example"), T_("This is an example of a balloon popup notification!"));
}
-void NotificationsPage::update(size_t row, size_t column, bool enable) {
- table->setIcon(row, column, enable ? (column - COLUMN_TEXT) : 0);
- table->setText(row, column, enable ? T_("Yes") : T_("No"));
+void NotificationsPage::updateSound(size_t row) {
+ auto& s = options[row].sound;
+ table->setIcon(row, COLUMN_SOUND, s.empty() ? IMAGE_DISABLED : IMAGE_SOUND);
+ table->setText(row, COLUMN_SOUND, s.empty() ? T_("No") : (s == _T("beep")) ? T_("Beep") : T_("Custom"));
+}
+
+void NotificationsPage::updateBalloon(size_t row) {
+ auto& b = options[row].balloon;
+ table->setIcon(row, COLUMN_BALLOON, (b == SettingsManager::BALLOON_DISABLED) ? IMAGE_DISABLED : IMAGE_BALLOON);
+ table->setText(row, COLUMN_BALLOON, (b == SettingsManager::BALLOON_DISABLED) ? T_("No") :
+ (b == SettingsManager::BALLOON_ALWAYS) ? T_("Yes") : T_("Yes (bg)"));
}
=== modified file 'win32/NotificationsPage.h'
--- win32/NotificationsPage.h 2011-04-23 10:33:55 +0000
+++ win32/NotificationsPage.h 2011-04-25 21:52:03 +0000
@@ -36,7 +36,7 @@
int soundSetting;
tstring sound;
int balloonSetting;
- bool balloon;
+ int balloon;
unsigned helpId;
};
static Option options[];
@@ -49,13 +49,19 @@
COLUMN_LAST
};
+ enum {
+ IMAGE_DISABLED,
+ IMAGE_SOUND,
+ IMAGE_BALLOON
+ };
+
TablePtr table;
CheckBoxPtr sound;
CheckBoxPtr balloon;
- GroupBoxPtr beepGroup;
- TextBoxPtr beepFile;
-
- int prevSelection;
+ GroupBoxPtr soundGroup;
+ TextBoxPtr soundFile;
+ GroupBoxPtr balloonGroup;
+ CheckBoxPtr balloonBg;
void handleSelectionChanged();
void handleDblClicked();
@@ -64,10 +70,13 @@
void handleSoundClicked();
void handleBalloonClicked();
void handlePlayClicked();
+ void handleSoundChanged();
void handleBrowseClicked();
+ void handleBalloonBgClicked();
void handleExampleClicked();
- void update(size_t row, size_t column, bool enable);
+ void updateSound(size_t row);
+ void updateBalloon(size_t row);
};
#endif // !defined(DCPLUSPLUS_WIN32_NOTIFICATIONS_PAGE_H)
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-04-23 10:33:55 +0000
+++ win32/WinUtil.cpp 2011-04-25 21:52:03 +0000
@@ -544,7 +544,8 @@
playSound(Text::toT(s));
}
- if(SettingsManager::getInstance()->getBool((SettingsManager::IntSetting)balloonSetting)) {
+ int b = SettingsManager::getInstance()->get((SettingsManager::IntSetting)balloonSetting);
+ if(b == SettingsManager::BALLOON_ALWAYS || (b == SettingsManager::BALLOON_BACKGROUND && !mainWindow->onForeground())) {
mainWindow->notify(balloonTitle, balloonText);
}
}