Add common message dialog

This commit is contained in:
Jonas Kvinge 2023-04-18 17:44:42 +02:00
parent b637867f9e
commit b273a449e3
7 changed files with 144 additions and 50 deletions

View File

@ -208,6 +208,7 @@ set(SOURCES
dialogs/userpassdialog.cpp
dialogs/deleteconfirmationdialog.cpp
dialogs/lastfmimportdialog.cpp
dialogs/messagedialog.cpp
dialogs/snapdialog.cpp
dialogs/saveplaylistsdialog.cpp
@ -444,6 +445,7 @@ set(HEADERS
dialogs/userpassdialog.h
dialogs/deleteconfirmationdialog.h
dialogs/lastfmimportdialog.h
dialogs/messagedialog.h
dialogs/snapdialog.h
dialogs/saveplaylistsdialog.h
@ -570,7 +572,7 @@ set(UI
dialogs/addstreamdialog.ui
dialogs/userpassdialog.ui
dialogs/lastfmimportdialog.ui
dialogs/snapdialog.ui
dialogs/messagedialog.ui
dialogs/saveplaylistsdialog.ui
widgets/trackslider.ui

View File

@ -1030,12 +1030,13 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
#ifdef Q_OS_LINUX
if (!Utilities::GetEnv("SNAP").isEmpty() && !Utilities::GetEnv("SNAP_NAME").isEmpty()) {
s.beginGroup(kSettingsGroup);
if (!s.value("ignore_snap", false).toBool()) {
SnapDialog *snap_dialog = new SnapDialog();
const bool ignore_snap = s.value("ignore_snap", false).toBool();
s.endGroup();
if (!ignore_snap) {
SnapDialog *snap_dialog = new SnapDialog(this);
snap_dialog->setAttribute(Qt::WA_DeleteOnClose);
snap_dialog->show();
}
s.endGroup();
}
#endif

View File

@ -0,0 +1,57 @@
/*
* Strawberry Music Player
* Copyright 2020-2023, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QDialog>
#include <QDialogButtonBox>
#include <QString>
#include <QLabel>
#include <QPushButton>
#include <QKeySequence>
#include <QCheckBox>
#include <QSettings>
#include "messagedialog.h"
#include "ui_messagedialog.h"
MessageDialog::MessageDialog(QWidget *parent) : QDialog(parent), ui_(new Ui_MessageDialog) {
ui_->setupUi(this);
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
ui_->buttonBox->button(QDialogButtonBox::Ok)->setShortcut(QKeySequence::Close);
QObject::connect(ui_->checkbox_do_not_show_message_again, &QCheckBox::toggled, this, &MessageDialog::DoNotShowMessageAgain);
}
MessageDialog::~MessageDialog() { delete ui_; }
void MessageDialog::DoNotShowMessageAgain() {
if (!settings_group_.isEmpty() && !do_not_show_message_again_.isEmpty()) {
QSettings s;
s.beginGroup(settings_group_);
s.setValue(do_not_show_message_again_, ui_->checkbox_do_not_show_message_again->isChecked());
s.endGroup();
}
}

View File

@ -0,0 +1,46 @@
/*
* Strawberry Music Player
* Copyright 2020-2023, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MESSAGEDIALOG_H
#define MESSAGEDIALOG_H
#include <QDialog>
class Ui_MessageDialog;
class MessageDialog : public QDialog {
Q_OBJECT
public:
explicit MessageDialog(QWidget *parent = nullptr);
~MessageDialog() override;
void set_settings_group(const QString &settings_group) { settings_group_ = settings_group; }
void set_do_not_show_message_again(const QString &do_not_show_message_again) { do_not_show_message_again_ = do_not_show_message_again; }
private slots:
void DoNotShowMessageAgain();
protected:
Ui_MessageDialog *ui_;
QString settings_group_;
QString do_not_show_message_again_;
};
#endif // MESSAGEDIALOG_H

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SnapDialog</class>
<widget class="QDialog" name="SnapDialog">
<class>MessageDialog</class>
<widget class="QDialog" name="MessageDialog">
<property name="geometry">
<rect>
<x>0</x>
@ -14,7 +14,7 @@
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>Strawberry is running as a snap</string>
<string>Message Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="../../data/icons.qrc">
@ -46,6 +46,12 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
@ -121,7 +127,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SnapDialog</receiver>
<receiver>MessageDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -137,7 +143,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SnapDialog</receiver>
<receiver>MessageDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2020-2023, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,28 +17,26 @@
*
*/
#include "config.h"
#include <QDialog>
#include <QDialogButtonBox>
#include <QString>
#include <QFont>
#include <QLabel>
#include <QPushButton>
#include <QKeySequence>
#include <QSettings>
#include "core/logging.h"
#include "core/iconloader.h"
#include "core/mainwindow.h"
#include "utilities/screenutils.h"
#include "snapdialog.h"
#include "ui_snapdialog.h"
#include "ui_messagedialog.h"
#include "core/mainwindow.h"
SnapDialog::SnapDialog(QWidget *parent) : MessageDialog(parent) {
SnapDialog::SnapDialog(QWidget *parent) : QDialog(parent), ui_(new Ui_SnapDialog) {
ui_->setupUi(this);
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
setWindowTitle(tr("Strawberry is running as a Snap"));
const QIcon icon = IconLoader::Load("dialog-warning");
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const QPixmap pixmap = icon.pixmap(QSize(64, 64), devicePixelRatioF());
#else
const QPixmap pixmap = icon.pixmap(QSize(64, 64));
#endif
ui_->label_logo->setPixmap(pixmap);
QString text;
text += QString("<p>");
text += tr("It is detected that Strawberry is running as a Snap");
@ -88,19 +86,11 @@ SnapDialog::SnapDialog(QWidget *parent) : QDialog(parent), ui_(new Ui_SnapDialog
ui_->label_text->adjustSize();
adjustSize();
ui_->buttonBox->button(QDialogButtonBox::Ok)->setShortcut(QKeySequence::Close);
settings_group_ = MainWindow::kSettingsGroup;
do_not_show_message_again_ = "ignore_snap";
QObject::connect(ui_->checkbox_do_not_show_message_again, &QCheckBox::toggled, this, &SnapDialog::DoNotShowMessageAgain);
}
SnapDialog::~SnapDialog() { delete ui_; }
void SnapDialog::DoNotShowMessageAgain() {
QSettings s;
s.beginGroup(MainWindow::kSettingsGroup);
s.setValue("ignore_snap", ui_->checkbox_do_not_show_message_again->isChecked());
s.endGroup();
if (parent) {
Utilities::CenterWidgetOnScreen(Utilities::GetScreen(parent), this);
}
}

View File

@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2020-2023, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,22 +20,14 @@
#ifndef SNAPDIALOG_H
#define SNAPDIALOG_H
#include <QDialog>
#include "messagedialog.h"
class Ui_SnapDialog;
class SnapDialog : public QDialog {
class SnapDialog : public MessageDialog {
Q_OBJECT
public:
explicit SnapDialog(QWidget *parent = nullptr);
~SnapDialog() override;
private slots:
void DoNotShowMessageAgain();
private:
Ui_SnapDialog *ui_;
};
#endif // SNAPDIALOG_H