Feature/3139 new features for tips (#3152)
* "Tip of the Day" option added to Help menu * Tip of the Day setting moved * If no new tips are availabe, don't show tip of the day again * list storing try #1 * first unseen tip shown first * lastShownTip removed * fixed next/previous buttons * spaces > tab * "Show this window on startup" is not checked by default
This commit is contained in:
parent
6374d157fc
commit
e1394bd851
8 changed files with 62 additions and 22 deletions
|
@ -93,15 +93,15 @@ GeneralSettingsPage::GeneralSettingsPage()
|
||||||
personalGrid->addWidget(&pixmapCacheLabel, 2, 0);
|
personalGrid->addWidget(&pixmapCacheLabel, 2, 0);
|
||||||
personalGrid->addWidget(&pixmapCacheEdit, 2, 1);
|
personalGrid->addWidget(&pixmapCacheEdit, 2, 1);
|
||||||
personalGrid->addWidget(&updateNotificationCheckBox, 3, 0);
|
personalGrid->addWidget(&updateNotificationCheckBox, 3, 0);
|
||||||
personalGrid->addWidget(&picDownloadCheckBox, 4, 0, 1, 3);
|
personalGrid->addWidget(&showTipsOnStartup, 4, 0);
|
||||||
personalGrid->addWidget(&defaultUrlLabel, 5, 0, 1, 1);
|
personalGrid->addWidget(&picDownloadCheckBox, 5, 0);
|
||||||
personalGrid->addWidget(defaultUrlEdit, 5, 1, 1, 1);
|
personalGrid->addWidget(&urlLinkLabel, 5, 1);
|
||||||
personalGrid->addWidget(&defaultUrlRestoreButton, 5, 2, 1, 1);
|
personalGrid->addWidget(&defaultUrlLabel, 6, 0, 1, 1);
|
||||||
personalGrid->addWidget(&fallbackUrlLabel, 6, 0, 1, 1);
|
personalGrid->addWidget(defaultUrlEdit, 6, 1, 1, 1);
|
||||||
personalGrid->addWidget(fallbackUrlEdit, 6, 1, 1, 1);
|
personalGrid->addWidget(&defaultUrlRestoreButton, 6, 2, 1, 1);
|
||||||
personalGrid->addWidget(&fallbackUrlRestoreButton, 6, 2, 1, 1);
|
personalGrid->addWidget(&fallbackUrlLabel, 7, 0, 1, 1);
|
||||||
personalGrid->addWidget(&showTipsOnStartup, 7, 0);
|
personalGrid->addWidget(fallbackUrlEdit, 7, 1, 1, 1);
|
||||||
personalGrid->addWidget(&urlLinkLabel, 7, 1, 1, 1);
|
personalGrid->addWidget(&fallbackUrlRestoreButton, 7, 2, 1, 1);
|
||||||
personalGrid->addWidget(&clearDownloadedPicsButton, 8, 0, 1, 3);
|
personalGrid->addWidget(&clearDownloadedPicsButton, 8, 0, 1, 3);
|
||||||
|
|
||||||
urlLinkLabel.setTextInteractionFlags(Qt::LinksAccessibleByMouse);
|
urlLinkLabel.setTextInteractionFlags(Qt::LinksAccessibleByMouse);
|
||||||
|
|
|
@ -41,7 +41,19 @@ DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent)
|
||||||
tipNumber = new QLabel();
|
tipNumber = new QLabel();
|
||||||
tipNumber->setAlignment(Qt::AlignCenter);
|
tipNumber->setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
currentTip = settingsCache->getLastShownTip() + 1;
|
if (settingsCache->getSeenTips().size() != tipDatabase->rowCount()) {
|
||||||
|
newTipsAvailable = true;
|
||||||
|
QList<int> rangeToMaxTips;
|
||||||
|
for (int i = 0; i < tipDatabase->rowCount(); i++) {
|
||||||
|
rangeToMaxTips.append(i);
|
||||||
|
}
|
||||||
|
QSet<int> unseenTips = rangeToMaxTips.toSet() - settingsCache->getSeenTips().toSet();
|
||||||
|
currentTip = *std::min_element(unseenTips.begin(), unseenTips.end());
|
||||||
|
} else {
|
||||||
|
newTipsAvailable = false;
|
||||||
|
currentTip = 0;
|
||||||
|
}
|
||||||
|
|
||||||
connect(this, SIGNAL(newTipRequested(int)), this, SLOT(updateTip(int)));
|
connect(this, SIGNAL(newTipRequested(int)), this, SLOT(updateTip(int)));
|
||||||
newTipRequested(currentTip);
|
newTipRequested(currentTip);
|
||||||
|
|
||||||
|
@ -63,7 +75,7 @@ DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent)
|
||||||
connect(previousButton, SIGNAL(clicked()), this, SLOT(previousClicked()));
|
connect(previousButton, SIGNAL(clicked()), this, SLOT(previousClicked()));
|
||||||
|
|
||||||
showTipsOnStartupCheck = new QCheckBox("Show tips on startup");
|
showTipsOnStartupCheck = new QCheckBox("Show tips on startup");
|
||||||
showTipsOnStartupCheck->setChecked(true);
|
showTipsOnStartupCheck->setChecked(settingsCache->getShowTipsOnStartup());
|
||||||
connect(showTipsOnStartupCheck, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool)));
|
connect(showTipsOnStartupCheck, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool)));
|
||||||
buttonBar = new QHBoxLayout();
|
buttonBar = new QHBoxLayout();
|
||||||
buttonBar->addWidget(showTipsOnStartupCheck);
|
buttonBar->addWidget(showTipsOnStartupCheck);
|
||||||
|
@ -118,6 +130,13 @@ void DlgTipOfTheDay::updateTip(int tipId)
|
||||||
tipId = tipId % tipDatabase->rowCount();
|
tipId = tipId % tipDatabase->rowCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store tip id as seen
|
||||||
|
QList<int> seenTips = settingsCache->getSeenTips();
|
||||||
|
if (!seenTips.contains(tipId)) {
|
||||||
|
seenTips.append(tipId);
|
||||||
|
settingsCache->setSeenTips(seenTips);
|
||||||
|
}
|
||||||
|
|
||||||
TipOfTheDay tip = tipDatabase->getTip(tipId);
|
TipOfTheDay tip = tipDatabase->getTip(tipId);
|
||||||
titleText = tip.getTitle();
|
titleText = tip.getTitle();
|
||||||
contentText = tip.getContent();
|
contentText = tip.getContent();
|
||||||
|
@ -140,7 +159,6 @@ void DlgTipOfTheDay::updateTip(int tipId)
|
||||||
tipNumber->setText("Tip " + QString::number(tipId + 1) + " / " + QString::number(tipDatabase->rowCount()));
|
tipNumber->setText("Tip " + QString::number(tipId + 1) + " / " + QString::number(tipDatabase->rowCount()));
|
||||||
|
|
||||||
currentTip = static_cast<unsigned int>(tipId);
|
currentTip = static_cast<unsigned int>(tipId);
|
||||||
settingsCache->setLastShownTip(currentTip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgTipOfTheDay::resizeEvent(QResizeEvent *event)
|
void DlgTipOfTheDay::resizeEvent(QResizeEvent *event)
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
explicit DlgTipOfTheDay(QWidget *parent = nullptr);
|
explicit DlgTipOfTheDay(QWidget *parent = nullptr);
|
||||||
~DlgTipOfTheDay() override;
|
~DlgTipOfTheDay() override;
|
||||||
bool successfulInit;
|
bool successfulInit;
|
||||||
|
bool newTipsAvailable;
|
||||||
signals:
|
signals:
|
||||||
void newTipRequested(int tipId);
|
void newTipRequested(int tipId);
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ int main(int argc, char *argv[])
|
||||||
qDebug("main(): ui.show() finished");
|
qDebug("main(): ui.show() finished");
|
||||||
|
|
||||||
DlgTipOfTheDay tip;
|
DlgTipOfTheDay tip;
|
||||||
if (settingsCache->getShowTipsOnStartup() && tip.successfulInit) {
|
if (tip.successfulInit && settingsCache->getShowTipsOnStartup() && tip.newTipsAvailable) {
|
||||||
tip.show();
|
tip.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,7 @@ QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaul
|
||||||
tmp = defaultPath;
|
tmp = defaultPath;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsCache::SettingsCache()
|
SettingsCache::SettingsCache()
|
||||||
{
|
{
|
||||||
// first, figure out if we are running in portable mode
|
// first, figure out if we are running in portable mode
|
||||||
|
@ -181,7 +182,9 @@ SettingsCache::SettingsCache()
|
||||||
|
|
||||||
// tip of the day settings
|
// tip of the day settings
|
||||||
showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool();
|
showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool();
|
||||||
lastShownTip = settings->value("tipOfDay/lastShown", -1).toInt();
|
for (auto tipNumber : settings->value("tipOfDay/seenTips").toList()) {
|
||||||
|
seenTips.append(tipNumber.toInt());
|
||||||
|
}
|
||||||
|
|
||||||
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/");
|
||||||
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
||||||
|
@ -345,10 +348,14 @@ void SettingsCache::setShowTipsOnStartup(bool _showTipsOnStartup)
|
||||||
settings->setValue("tipOfDay/showTips", showTipsOnStartup);
|
settings->setValue("tipOfDay/showTips", showTipsOnStartup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setLastShownTip(int _lastShownTip)
|
void SettingsCache::setSeenTips(const QList<int> &_seenTips)
|
||||||
{
|
{
|
||||||
lastShownTip = _lastShownTip;
|
seenTips = _seenTips;
|
||||||
settings->setValue("tipOfDay/lastShown", lastShownTip);
|
QList<QVariant> storedTipList;
|
||||||
|
for (auto tipNumber : seenTips) {
|
||||||
|
storedTipList.append(tipNumber);
|
||||||
|
}
|
||||||
|
settings->setValue("tipOfDay/seenTips", storedTipList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setDeckPath(const QString &_deckPath)
|
void SettingsCache::setDeckPath(const QString &_deckPath)
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
spoilerDatabasePath, tokenDatabasePath, themeName;
|
spoilerDatabasePath, tokenDatabasePath, themeName;
|
||||||
bool notifyAboutUpdates;
|
bool notifyAboutUpdates;
|
||||||
bool showTipsOnStartup;
|
bool showTipsOnStartup;
|
||||||
unsigned int lastShownTip;
|
QList<int> seenTips;
|
||||||
bool mbDownloadSpoilers;
|
bool mbDownloadSpoilers;
|
||||||
int updateReleaseChannel;
|
int updateReleaseChannel;
|
||||||
int maxFontSize;
|
int maxFontSize;
|
||||||
|
@ -205,9 +205,9 @@ public:
|
||||||
{
|
{
|
||||||
return showTipsOnStartup;
|
return showTipsOnStartup;
|
||||||
}
|
}
|
||||||
unsigned int getLastShownTip() const
|
QList<int> getSeenTips() const
|
||||||
{
|
{
|
||||||
return lastShownTip;
|
return seenTips;
|
||||||
}
|
}
|
||||||
ReleaseChannel *getUpdateReleaseChannel() const
|
ReleaseChannel *getUpdateReleaseChannel() const
|
||||||
{
|
{
|
||||||
|
@ -444,7 +444,7 @@ public slots:
|
||||||
void setTokenDialogGeometry(const QByteArray &_tokenDialog);
|
void setTokenDialogGeometry(const QByteArray &_tokenDialog);
|
||||||
void setLang(const QString &_lang);
|
void setLang(const QString &_lang);
|
||||||
void setShowTipsOnStartup(bool _showTipsOnStartup);
|
void setShowTipsOnStartup(bool _showTipsOnStartup);
|
||||||
void setLastShownTip(int _lastShowTip);
|
void setSeenTips(const QList<int> &_seenTips);
|
||||||
void setDeckPath(const QString &_deckPath);
|
void setDeckPath(const QString &_deckPath);
|
||||||
void setReplaysPath(const QString &_replaysPath);
|
void setReplaysPath(const QString &_replaysPath);
|
||||||
void setPicsPath(const QString &_picsPath);
|
void setPicsPath(const QString &_picsPath);
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "dlg_forgotpasswordreset.h"
|
#include "dlg_forgotpasswordreset.h"
|
||||||
#include "dlg_register.h"
|
#include "dlg_register.h"
|
||||||
#include "dlg_settings.h"
|
#include "dlg_settings.h"
|
||||||
|
#include "dlg_tip_of_the_day.h"
|
||||||
#include "dlg_update.h"
|
#include "dlg_update.h"
|
||||||
#include "dlg_viewlog.h"
|
#include "dlg_viewlog.h"
|
||||||
#include "localclient.h"
|
#include "localclient.h"
|
||||||
|
@ -312,6 +313,14 @@ void MainWindow::actAbout()
|
||||||
mb.exec();
|
mb.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::actTips()
|
||||||
|
{
|
||||||
|
DlgTipOfTheDay tip;
|
||||||
|
if (tip.successfulInit) {
|
||||||
|
tip.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::actUpdate()
|
void MainWindow::actUpdate()
|
||||||
{
|
{
|
||||||
DlgUpdate dlg(this);
|
DlgUpdate dlg(this);
|
||||||
|
@ -627,6 +636,7 @@ void MainWindow::retranslateUi()
|
||||||
aEditTokens->setText(tr("Edit &tokens..."));
|
aEditTokens->setText(tr("Edit &tokens..."));
|
||||||
|
|
||||||
aAbout->setText(tr("&About Cockatrice"));
|
aAbout->setText(tr("&About Cockatrice"));
|
||||||
|
aTips->setText(tr("&Tip of the Day"));
|
||||||
aUpdate->setText(tr("Check for Client Updates"));
|
aUpdate->setText(tr("Check for Client Updates"));
|
||||||
aViewLog->setText(tr("View &debug log"));
|
aViewLog->setText(tr("View &debug log"));
|
||||||
helpMenu->setTitle(tr("&Help"));
|
helpMenu->setTitle(tr("&Help"));
|
||||||
|
@ -659,6 +669,8 @@ void MainWindow::createActions()
|
||||||
|
|
||||||
aAbout = new QAction(this);
|
aAbout = new QAction(this);
|
||||||
connect(aAbout, SIGNAL(triggered()), this, SLOT(actAbout()));
|
connect(aAbout, SIGNAL(triggered()), this, SLOT(actAbout()));
|
||||||
|
aTips = new QAction(this);
|
||||||
|
connect(aTips, SIGNAL(triggered()), this, SLOT(actTips()));
|
||||||
aUpdate = new QAction(this);
|
aUpdate = new QAction(this);
|
||||||
connect(aUpdate, SIGNAL(triggered()), this, SLOT(actUpdate()));
|
connect(aUpdate, SIGNAL(triggered()), this, SLOT(actUpdate()));
|
||||||
aViewLog = new QAction(this);
|
aViewLog = new QAction(this);
|
||||||
|
@ -729,6 +741,7 @@ void MainWindow::createMenus()
|
||||||
|
|
||||||
helpMenu = menuBar()->addMenu(QString());
|
helpMenu = menuBar()->addMenu(QString());
|
||||||
helpMenu->addAction(aAbout);
|
helpMenu->addAction(aAbout);
|
||||||
|
helpMenu->addAction(aTips);
|
||||||
helpMenu->addAction(aUpdate);
|
helpMenu->addAction(aUpdate);
|
||||||
helpMenu->addAction(aViewLog);
|
helpMenu->addAction(aViewLog);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ private slots:
|
||||||
void actExit();
|
void actExit();
|
||||||
void actForgotPasswordRequest();
|
void actForgotPasswordRequest();
|
||||||
void actAbout();
|
void actAbout();
|
||||||
|
void actTips();
|
||||||
void actUpdate();
|
void actUpdate();
|
||||||
void actViewLog();
|
void actViewLog();
|
||||||
void forgotPasswordSuccess();
|
void forgotPasswordSuccess();
|
||||||
|
@ -115,7 +116,7 @@ private:
|
||||||
QList<QMenu *> tabMenus;
|
QList<QMenu *> tabMenus;
|
||||||
QMenu *cockatriceMenu, *dbMenu, *helpMenu;
|
QMenu *cockatriceMenu, *dbMenu, *helpMenu;
|
||||||
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
|
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
|
||||||
*aAbout, *aCheckCardUpdates, *aRegister, *aUpdate, *aViewLog;
|
*aAbout, *aTips, *aCheckCardUpdates, *aRegister, *aUpdate, *aViewLog;
|
||||||
QAction *aManageSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
|
QAction *aManageSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue