2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2009 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
|
2009-08-19 18:15:16 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-07-23 13:11:51 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <rshare.h>
|
|
|
|
#include "NotifyPage.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsnotify.h>
|
2013-01-08 17:07:52 -05:00
|
|
|
#include <retroshare/rsplugin.h>
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "rsharesettings.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
#include "gui/MainWindow.h"
|
2012-08-05 16:12:55 -04:00
|
|
|
#include "gui/common/UserNotify.h"
|
2013-01-08 17:07:52 -05:00
|
|
|
#include "gui/common/FeedNotify.h"
|
2012-09-04 16:04:49 -04:00
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
#include "gui/NewsFeed.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
NotifyPage::NotifyPage(QWidget * parent, Qt::WFlags flags)
|
2009-08-19 18:15:16 -04:00
|
|
|
: ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
connect(ui.notifyButton, SIGNAL(clicked()), this, SLOT(testNotify()));
|
|
|
|
connect(ui.toasterButton, SIGNAL(clicked()), this, SLOT(testToaster()));
|
|
|
|
|
2012-08-05 16:12:55 -04:00
|
|
|
QFont font = ui.notify_Peers->font(); // use font from existing checkbox
|
2013-01-08 17:07:52 -05:00
|
|
|
|
|
|
|
/* add feed notify */
|
|
|
|
int row = 0;
|
|
|
|
int pluginCount = rsPlugins->nbPlugins();
|
|
|
|
for (int i = 0; i < pluginCount; ++i) {
|
|
|
|
RsPlugin *rsPlugin = rsPlugins->plugin(i);
|
|
|
|
if (rsPlugin) {
|
|
|
|
FeedNotify *feedNotify = rsPlugin->qt_feedNotify();
|
|
|
|
if (feedNotify) {
|
|
|
|
QString name;
|
|
|
|
if (!feedNotify->hasSetting(name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCheckBox *enabledCheckBox = new QCheckBox(name, this);
|
|
|
|
enabledCheckBox->setFont(font);
|
|
|
|
ui.feedLayout->addWidget(enabledCheckBox, row++);
|
|
|
|
|
|
|
|
mFeedNotifySettingList.push_back(FeedNotifySetting(feedNotify, enabledCheckBox));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add user notify */
|
2012-08-05 16:12:55 -04:00
|
|
|
const QList<UserNotify*> &userNotifyList = MainWindow::getInstance()->getUserNotifyList();
|
|
|
|
QList<UserNotify*>::const_iterator it;
|
2013-01-08 17:07:52 -05:00
|
|
|
row = 0;
|
2012-08-05 16:12:55 -04:00
|
|
|
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);
|
2012-10-27 11:59:12 -04:00
|
|
|
ui.notifyLayout->addWidget(combinedCheckBox, row, 1);
|
2012-08-05 16:12:55 -04:00
|
|
|
|
2012-10-27 11:59:12 -04:00
|
|
|
QCheckBox *blinkCheckBox = new QCheckBox(tr("Blink"), this);
|
|
|
|
blinkCheckBox->setFont(font);
|
|
|
|
ui.notifyLayout->addWidget(blinkCheckBox, row++, 2);
|
|
|
|
|
|
|
|
mUserNotifySettingList.push_back(UserNotifySetting(userNotify, enabledCheckBox, combinedCheckBox, blinkCheckBox));
|
2012-08-05 16:12:55 -04:00
|
|
|
}
|
2011-07-13 15:24:33 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-07 19:58:17 -04:00
|
|
|
NotifyPage::~NotifyPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
uint NotifyPage::getNewsFlags()
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2012-09-04 16:04:49 -04:00
|
|
|
uint newsFlags = 0;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
if (ui.notify_Peers->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_PEER;
|
|
|
|
if (ui.notify_Channels->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_CHAN;
|
|
|
|
if (ui.notify_Forums->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_FORUM;
|
|
|
|
if (ui.notify_Blogs->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_BLOG;
|
|
|
|
if (ui.notify_Messages->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_MSG;
|
|
|
|
if (ui.notify_Chat->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_CHAT;
|
|
|
|
if (ui.notify_Security->isChecked())
|
|
|
|
newsFlags |= RS_FEED_TYPE_SECURITY;
|
|
|
|
|
|
|
|
return newsFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint NotifyPage::getNotifyFlags()
|
|
|
|
{
|
|
|
|
uint notifyFlags = 0;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
if (ui.popup_Connect->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_CONNECT;
|
2010-06-15 12:51:48 -04:00
|
|
|
if (ui.popup_NewMsg->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_MSG;
|
2010-11-24 19:20:25 -05:00
|
|
|
if (ui.popup_DownloadFinished->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_DOWNLOAD;
|
2012-03-30 19:02:52 -04:00
|
|
|
if (ui.popup_PrivateChat->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_CHAT;
|
2012-03-30 19:02:52 -04:00
|
|
|
if (ui.popup_GroupChat->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_GROUPCHAT;
|
2012-03-30 19:02:52 -04:00
|
|
|
if (ui.popup_ChatLobby->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_CHATLOBBY;
|
2012-04-25 15:19:16 -04:00
|
|
|
if (ui.popup_ConnectAttempt->isChecked())
|
2012-09-04 16:04:49 -04:00
|
|
|
notifyFlags |= RS_POPUP_CONNECT_ATTEMPT;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
return notifyFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
|
|
|
NotifyPage::save(QString &/*errmsg*/)
|
|
|
|
{
|
|
|
|
/* extract from rsNotify the flags */
|
|
|
|
|
|
|
|
uint messageflags = 0;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-04-26 19:41:14 -04:00
|
|
|
if (ui.message_ConnectAttempt->isChecked())
|
|
|
|
messageflags |= RS_MESSAGE_CONNECT_ATTEMPT;
|
|
|
|
|
2013-01-08 17:07:52 -05:00
|
|
|
/* save feed notify */
|
|
|
|
QList<FeedNotifySetting>::iterator feedNotifyIt;
|
|
|
|
for (feedNotifyIt = mFeedNotifySettingList.begin(); feedNotifyIt != mFeedNotifySettingList.end(); ++feedNotifyIt) {
|
|
|
|
feedNotifyIt->mFeedNotify->setNotifyEnabled(feedNotifyIt->mEnabledCheckBox->isChecked());
|
|
|
|
}
|
|
|
|
|
2012-08-05 16:12:55 -04:00
|
|
|
/* save user notify */
|
|
|
|
QList<UserNotifySetting>::iterator notifyIt;
|
|
|
|
for (notifyIt = mUserNotifySettingList.begin(); notifyIt != mUserNotifySettingList.end(); ++notifyIt) {
|
2012-10-27 11:59:12 -04:00
|
|
|
notifyIt->mUserNotify->setNotifyEnabled(notifyIt->mEnabledCheckBox->isChecked(), notifyIt->mCombinedCheckBox->isChecked(), notifyIt->mBlinkCheckBox->isChecked());
|
2012-08-05 16:12:55 -04:00
|
|
|
}
|
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
Settings->setNotifyFlags(getNotifyFlags());
|
|
|
|
Settings->setNewsFeedFlags(getNewsFlags());
|
2012-04-26 19:41:14 -04:00
|
|
|
Settings->setMessageFlags(messageflags);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-07-30 09:27:40 -04:00
|
|
|
Settings->setDisplayTrayChatLobby(ui.systray_ChatLobby->isChecked());
|
2010-06-15 12:51:48 -04:00
|
|
|
Settings->setDisplayTrayGroupChat(ui.systray_GroupChat->isChecked());
|
|
|
|
MainWindow::installGroupChatNotifier();
|
2010-11-25 19:54:18 -05:00
|
|
|
MainWindow::installNotifyIcons();
|
2010-06-15 12:51:48 -04:00
|
|
|
|
2010-09-01 16:54:24 -04:00
|
|
|
Settings->setAddFeedsAtEnd(ui.addFeedsAtEnd->isChecked());
|
|
|
|
|
2010-12-10 16:49:38 -05:00
|
|
|
int index = ui.comboBoxToasterPosition->currentIndex();
|
|
|
|
if (index != -1) {
|
|
|
|
Settings->setToasterPosition((RshareSettings::enumToasterPosition) ui.comboBoxToasterPosition->itemData(index).toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->setToasterMargin(QPoint(ui.spinBoxToasterXMargin->value(), ui.spinBoxToasterYMargin->value()));
|
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
load();
|
|
|
|
return true;
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void NotifyPage::load()
|
|
|
|
{
|
2010-06-15 12:51:48 -04:00
|
|
|
/* extract from rsNotify the flags */
|
2010-06-15 07:34:58 -04:00
|
|
|
uint notifyflags = Settings->getNotifyFlags();
|
|
|
|
uint newsflags = Settings->getNewsFeedFlags();
|
2012-04-26 19:41:14 -04:00
|
|
|
uint messageflags = Settings->getMessageFlags();
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
ui.popup_Connect->setChecked(notifyflags & RS_POPUP_CONNECT);
|
|
|
|
ui.popup_NewMsg->setChecked(notifyflags & RS_POPUP_MSG);
|
2010-11-24 19:20:25 -05:00
|
|
|
ui.popup_DownloadFinished->setChecked(notifyflags & RS_POPUP_DOWNLOAD);
|
2012-03-30 19:02:52 -04:00
|
|
|
ui.popup_PrivateChat->setChecked(notifyflags & RS_POPUP_CHAT);
|
|
|
|
ui.popup_GroupChat->setChecked(notifyflags & RS_POPUP_GROUPCHAT);
|
|
|
|
ui.popup_ChatLobby->setChecked(notifyflags & RS_POPUP_CHATLOBBY);
|
2012-04-25 15:19:16 -04:00
|
|
|
ui.popup_ConnectAttempt->setChecked(notifyflags & RS_POPUP_CONNECT_ATTEMPT);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
ui.notify_Peers->setChecked(newsflags & RS_FEED_TYPE_PEER);
|
|
|
|
ui.notify_Channels->setChecked(newsflags & RS_FEED_TYPE_CHAN);
|
|
|
|
ui.notify_Forums->setChecked(newsflags & RS_FEED_TYPE_FORUM);
|
|
|
|
ui.notify_Blogs->setChecked(newsflags & RS_FEED_TYPE_BLOG);
|
|
|
|
ui.notify_Chat->setChecked(newsflags & RS_FEED_TYPE_CHAT);
|
|
|
|
ui.notify_Messages->setChecked(newsflags & RS_FEED_TYPE_MSG);
|
2010-08-31 13:13:52 -04:00
|
|
|
ui.notify_Chat->setChecked(newsflags & RS_FEED_TYPE_CHAT);
|
2011-08-21 18:28:19 -04:00
|
|
|
ui.notify_Security->setChecked(newsflags & RS_FEED_TYPE_SECURITY);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-04-26 19:41:14 -04:00
|
|
|
ui.message_ConnectAttempt->setChecked(messageflags & RS_MESSAGE_CONNECT_ATTEMPT);
|
|
|
|
|
2010-06-15 12:51:48 -04:00
|
|
|
ui.systray_GroupChat->setChecked(Settings->getDisplayTrayGroupChat());
|
2012-07-30 09:27:40 -04:00
|
|
|
ui.systray_ChatLobby->setChecked(Settings->getDisplayTrayChatLobby());
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-09-01 16:54:24 -04:00
|
|
|
ui.addFeedsAtEnd->setChecked(Settings->getAddFeedsAtEnd());
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-12-10 16:49:38 -05:00
|
|
|
RshareSettings::enumToasterPosition toasterPosition = Settings->getToasterPosition();
|
|
|
|
ui.comboBoxToasterPosition->clear();
|
|
|
|
|
|
|
|
QMap<int, QString> toasterPositions;
|
|
|
|
toasterPositions[RshareSettings::TOASTERPOS_TOPLEFT] = tr("Top Left");
|
|
|
|
toasterPositions[RshareSettings::TOASTERPOS_TOPRIGHT] = tr("Top Right");
|
|
|
|
toasterPositions[RshareSettings::TOASTERPOS_BOTTOMLEFT] = tr("Bottom Left");
|
|
|
|
toasterPositions[RshareSettings::TOASTERPOS_BOTTOMRIGHT] = tr("Bottom Right");
|
|
|
|
|
|
|
|
QMap<int, QString>::iterator it;
|
|
|
|
int index = 0;
|
|
|
|
for (it = toasterPositions.begin(); it != toasterPositions.end(); it++, index++) {
|
|
|
|
ui.comboBoxToasterPosition->addItem(it.value(), it.key());
|
|
|
|
|
|
|
|
if (it.key() == toasterPosition) {
|
|
|
|
ui.comboBoxToasterPosition->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint margin = Settings->getToasterMargin();
|
|
|
|
ui.spinBoxToasterXMargin->setValue(margin.x());
|
|
|
|
ui.spinBoxToasterYMargin->setValue(margin.y());
|
2011-07-13 15:24:33 -04:00
|
|
|
|
2013-01-08 17:07:52 -05:00
|
|
|
/* load feed notify */
|
|
|
|
QList<FeedNotifySetting>::iterator feedNotifyIt;
|
|
|
|
for (feedNotifyIt = mFeedNotifySettingList.begin(); feedNotifyIt != mFeedNotifySettingList.end(); ++feedNotifyIt) {
|
|
|
|
feedNotifyIt->mEnabledCheckBox->setChecked(feedNotifyIt->mFeedNotify->notifyEnabled());
|
|
|
|
}
|
|
|
|
|
2012-08-05 16:12:55 -04:00
|
|
|
/* load user notify */
|
2013-01-08 17:07:52 -05:00
|
|
|
QList<UserNotifySetting>::iterator userNotifyIt;
|
|
|
|
for (userNotifyIt = mUserNotifySettingList.begin(); userNotifyIt != mUserNotifySettingList.end(); ++userNotifyIt) {
|
|
|
|
userNotifyIt->mEnabledCheckBox->setChecked(userNotifyIt->mUserNotify->notifyEnabled());
|
|
|
|
userNotifyIt->mCombinedCheckBox->setChecked(userNotifyIt->mUserNotify->notifyCombined());
|
|
|
|
userNotifyIt->mBlinkCheckBox->setChecked(userNotifyIt->mUserNotify->notifyBlink());
|
2012-08-05 16:12:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
notifyToggled();
|
2011-07-13 15:24:33 -04:00
|
|
|
}
|
|
|
|
|
2012-08-05 16:12:55 -04:00
|
|
|
void NotifyPage::notifyToggled()
|
2011-07-13 15:24:33 -04:00
|
|
|
{
|
2012-08-05 16:12:55 -04:00
|
|
|
QList<UserNotifySetting>::iterator notifyIt;
|
|
|
|
for (notifyIt = mUserNotifySettingList.begin(); notifyIt != mUserNotifySettingList.end(); ++notifyIt) {
|
|
|
|
if (notifyIt->mEnabledCheckBox->isChecked()) {
|
|
|
|
notifyIt->mCombinedCheckBox->setEnabled(true);
|
2012-10-27 11:59:12 -04:00
|
|
|
notifyIt->mBlinkCheckBox->setEnabled(true);
|
2011-07-13 15:24:33 -04:00
|
|
|
} else {
|
2012-08-05 16:12:55 -04:00
|
|
|
notifyIt->mCombinedCheckBox->setChecked(false);
|
|
|
|
notifyIt->mCombinedCheckBox->setEnabled(false);
|
2012-10-27 11:59:12 -04:00
|
|
|
|
|
|
|
notifyIt->mBlinkCheckBox->setChecked(false);
|
|
|
|
notifyIt->mBlinkCheckBox->setEnabled(false);
|
2011-07-13 15:24:33 -04:00
|
|
|
}
|
|
|
|
}
|
2010-12-10 16:49:38 -05:00
|
|
|
}
|
2012-09-04 16:04:49 -04:00
|
|
|
|
|
|
|
void NotifyPage::testNotify()
|
|
|
|
{
|
|
|
|
NewsFeed::testFeeds(getNewsFlags());
|
2013-01-14 17:41:31 -05:00
|
|
|
|
|
|
|
/* notify of plugins */
|
|
|
|
QList<FeedNotifySetting>::iterator feedNotifyIt;
|
|
|
|
for (feedNotifyIt = mFeedNotifySettingList.begin(); feedNotifyIt != mFeedNotifySettingList.end(); ++feedNotifyIt) {
|
|
|
|
if (feedNotifyIt->mEnabledCheckBox->isChecked()) {
|
|
|
|
NewsFeed::testFeed(feedNotifyIt->mFeedNotify);
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 16:04:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyPage::testToaster()
|
|
|
|
{
|
|
|
|
NotifyQt::getInstance()->testToaster(getNotifyFlags(), (RshareSettings::enumToasterPosition) ui.comboBoxToasterPosition->itemData(ui.comboBoxToasterPosition->currentIndex()).toInt(), QPoint(ui.spinBoxToasterXMargin->value(), ui.spinBoxToasterYMargin->value()));
|
|
|
|
}
|