Add common message dialog
This commit is contained in:
@@ -208,6 +208,7 @@ set(SOURCES
|
|||||||
dialogs/userpassdialog.cpp
|
dialogs/userpassdialog.cpp
|
||||||
dialogs/deleteconfirmationdialog.cpp
|
dialogs/deleteconfirmationdialog.cpp
|
||||||
dialogs/lastfmimportdialog.cpp
|
dialogs/lastfmimportdialog.cpp
|
||||||
|
dialogs/messagedialog.cpp
|
||||||
dialogs/snapdialog.cpp
|
dialogs/snapdialog.cpp
|
||||||
dialogs/saveplaylistsdialog.cpp
|
dialogs/saveplaylistsdialog.cpp
|
||||||
|
|
||||||
@@ -444,6 +445,7 @@ set(HEADERS
|
|||||||
dialogs/userpassdialog.h
|
dialogs/userpassdialog.h
|
||||||
dialogs/deleteconfirmationdialog.h
|
dialogs/deleteconfirmationdialog.h
|
||||||
dialogs/lastfmimportdialog.h
|
dialogs/lastfmimportdialog.h
|
||||||
|
dialogs/messagedialog.h
|
||||||
dialogs/snapdialog.h
|
dialogs/snapdialog.h
|
||||||
dialogs/saveplaylistsdialog.h
|
dialogs/saveplaylistsdialog.h
|
||||||
|
|
||||||
@@ -570,7 +572,7 @@ set(UI
|
|||||||
dialogs/addstreamdialog.ui
|
dialogs/addstreamdialog.ui
|
||||||
dialogs/userpassdialog.ui
|
dialogs/userpassdialog.ui
|
||||||
dialogs/lastfmimportdialog.ui
|
dialogs/lastfmimportdialog.ui
|
||||||
dialogs/snapdialog.ui
|
dialogs/messagedialog.ui
|
||||||
dialogs/saveplaylistsdialog.ui
|
dialogs/saveplaylistsdialog.ui
|
||||||
|
|
||||||
widgets/trackslider.ui
|
widgets/trackslider.ui
|
||||||
|
|||||||
@@ -1030,12 +1030,13 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
|||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
if (!Utilities::GetEnv("SNAP").isEmpty() && !Utilities::GetEnv("SNAP_NAME").isEmpty()) {
|
if (!Utilities::GetEnv("SNAP").isEmpty() && !Utilities::GetEnv("SNAP_NAME").isEmpty()) {
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
if (!s.value("ignore_snap", false).toBool()) {
|
const bool ignore_snap = s.value("ignore_snap", false).toBool();
|
||||||
SnapDialog *snap_dialog = new SnapDialog();
|
s.endGroup();
|
||||||
|
if (!ignore_snap) {
|
||||||
|
SnapDialog *snap_dialog = new SnapDialog(this);
|
||||||
snap_dialog->setAttribute(Qt::WA_DeleteOnClose);
|
snap_dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
snap_dialog->show();
|
snap_dialog->show();
|
||||||
}
|
}
|
||||||
s.endGroup();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
57
src/dialogs/messagedialog.cpp
Normal file
57
src/dialogs/messagedialog.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
src/dialogs/messagedialog.h
Normal file
46
src/dialogs/messagedialog.h
Normal 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
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>SnapDialog</class>
|
<class>MessageDialog</class>
|
||||||
<widget class="QDialog" name="SnapDialog">
|
<widget class="QDialog" name="MessageDialog">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<enum>Qt::StrongFocus</enum>
|
<enum>Qt::StrongFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Strawberry is running as a snap</string>
|
<string>Message Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowIcon">
|
<property name="windowIcon">
|
||||||
<iconset resource="../../data/icons.qrc">
|
<iconset resource="../../data/icons.qrc">
|
||||||
@@ -46,6 +46,12 @@
|
|||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -121,7 +127,7 @@
|
|||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>accepted()</signal>
|
<signal>accepted()</signal>
|
||||||
<receiver>SnapDialog</receiver>
|
<receiver>MessageDialog</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
@@ -137,7 +143,7 @@
|
|||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
<receiver>SnapDialog</receiver>
|
<receiver>MessageDialog</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Strawberry Music Player
|
* 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
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -17,28 +17,26 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "core/logging.h"
|
||||||
|
#include "core/iconloader.h"
|
||||||
#include <QDialog>
|
#include "core/mainwindow.h"
|
||||||
#include <QDialogButtonBox>
|
#include "utilities/screenutils.h"
|
||||||
#include <QString>
|
|
||||||
#include <QFont>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QKeySequence>
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
#include "snapdialog.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"));
|
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;
|
QString text;
|
||||||
text += QString("<p>");
|
text += QString("<p>");
|
||||||
text += tr("It is detected that Strawberry is running as a Snap");
|
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();
|
ui_->label_text->adjustSize();
|
||||||
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);
|
if (parent) {
|
||||||
|
Utilities::CenterWidgetOnScreen(Utilities::GetScreen(parent), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Strawberry Music Player
|
* 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
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,22 +20,14 @@
|
|||||||
#ifndef SNAPDIALOG_H
|
#ifndef SNAPDIALOG_H
|
||||||
#define SNAPDIALOG_H
|
#define SNAPDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include "messagedialog.h"
|
||||||
|
|
||||||
class Ui_SnapDialog;
|
class SnapDialog : public MessageDialog {
|
||||||
|
|
||||||
class SnapDialog : public QDialog {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SnapDialog(QWidget *parent = nullptr);
|
explicit SnapDialog(QWidget *parent = nullptr);
|
||||||
~SnapDialog() override;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void DoNotShowMessageAgain();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui_SnapDialog *ui_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SNAPDIALOG_H
|
#endif // SNAPDIALOG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user