605 lines
24 KiB
C++
605 lines
24 KiB
C++
|
|
||
|
#include "notification-ukcc-plugin.h"
|
||
|
#include "noticemenu.h"
|
||
|
#include <QFileDialog>
|
||
|
#include <QTimer>
|
||
|
#include <QFileSystemWatcher>
|
||
|
#include <QSettings>
|
||
|
#include <QToolButton>
|
||
|
#include <QFile>
|
||
|
#include <QThread>
|
||
|
|
||
|
#define THEME_QT_SCHEMA "org.ukui.style"
|
||
|
|
||
|
class ukToolButton : public QToolButton
|
||
|
{
|
||
|
public:
|
||
|
ukToolButton(QWidget *parent = nullptr):
|
||
|
QToolButton(parent)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
void paintEvent(QPaintEvent *event) override;
|
||
|
};
|
||
|
|
||
|
Notice::Notice()
|
||
|
{
|
||
|
m_pluginName = tr("Notice");
|
||
|
m_pluginType = SYSTEM;
|
||
|
|
||
|
if (QGSettings::isSchemaInstalled(THEME_QT_SCHEMA)) {
|
||
|
QByteArray id(THEME_QT_SCHEMA);
|
||
|
m_themeSetting = new QGSettings(id, QByteArray(), this);
|
||
|
}
|
||
|
if (!m_globalSettings) {
|
||
|
m_globalSettings = new UkuiNotification::NotificationGlobalSettings();
|
||
|
}
|
||
|
if (!m_appInfo) {
|
||
|
m_appInfo = new UkuiSearch::ApplicationInfo();
|
||
|
}
|
||
|
|
||
|
m_pluginWidget = new QWidget;
|
||
|
m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||
|
|
||
|
initUi(m_pluginWidget);
|
||
|
initSearchText();
|
||
|
initNoticeStatus();
|
||
|
initConnection();
|
||
|
initListUI();
|
||
|
}
|
||
|
|
||
|
Notice::~Notice()
|
||
|
{
|
||
|
if (m_globalSettings) {
|
||
|
delete m_globalSettings;
|
||
|
m_globalSettings = nullptr;
|
||
|
}
|
||
|
if (m_appInfo) {
|
||
|
delete m_appInfo;
|
||
|
m_appInfo = nullptr;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
QString Notice::plugini18nName()
|
||
|
{
|
||
|
return m_pluginName;
|
||
|
}
|
||
|
|
||
|
int Notice::pluginTypes()
|
||
|
{
|
||
|
return m_pluginType;
|
||
|
}
|
||
|
|
||
|
QWidget *Notice::pluginUi()
|
||
|
{
|
||
|
return m_pluginWidget;
|
||
|
}
|
||
|
|
||
|
const QString Notice::name() const
|
||
|
{
|
||
|
return QStringLiteral("Notice");
|
||
|
}
|
||
|
|
||
|
bool Notice::isShowOnHomePage() const
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
QIcon Notice::icon() const
|
||
|
{
|
||
|
return QIcon::fromTheme("ukui-tool-symbolic");
|
||
|
}
|
||
|
|
||
|
bool Notice::isEnable() const
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void Notice::initUi(QWidget *widget)
|
||
|
{
|
||
|
QVBoxLayout *mverticalLayout = new QVBoxLayout(widget);
|
||
|
mverticalLayout->setSpacing(0);
|
||
|
mverticalLayout->setContentsMargins(0, 0, 0, 0);
|
||
|
|
||
|
QFrame *notFazeFrame = new QFrame(widget);
|
||
|
initNotFaze(notFazeFrame);
|
||
|
|
||
|
QWidget *Noticewidget = new QWidget(widget);
|
||
|
Noticewidget->setMinimumSize(QSize(550, 0));
|
||
|
Noticewidget->setMaximumSize(QSize(16777215, 16777215));
|
||
|
|
||
|
QVBoxLayout *NoticeLayout = new QVBoxLayout(Noticewidget);
|
||
|
NoticeLayout->setContentsMargins(0, 0, 0, 0);
|
||
|
NoticeLayout->setSpacing(8);
|
||
|
|
||
|
m_noticeLabel = new TitleLabel(Noticewidget);
|
||
|
m_notFazeLabel = new TitleLabel();
|
||
|
m_notFazeLabel->setText(tr("NotFaze Mode"));
|
||
|
|
||
|
LightLabel *notFazeLabel = new LightLabel(tr("(Notification banners, prompts will be hidden, and notification sounds will be muted)"));
|
||
|
QFrame *distrubFrame = new QFrame(widget);
|
||
|
distrubFrame->setMinimumWidth(550);
|
||
|
distrubFrame->setMaximumWidth(16777215);
|
||
|
|
||
|
QHBoxLayout *distrubLyt = new QHBoxLayout(distrubFrame);
|
||
|
distrubLyt->setContentsMargins(0, 0, 0, 0);
|
||
|
distrubLyt->addWidget(m_notFazeLabel);
|
||
|
distrubLyt->addSpacing(4);
|
||
|
distrubLyt->addWidget(notFazeLabel, Qt::AlignLeft);
|
||
|
|
||
|
m_getNoticeFrame = new QFrame(Noticewidget);
|
||
|
m_getNoticeFrame->setMinimumSize(QSize(550, 60));
|
||
|
m_getNoticeFrame->setMaximumSize(QSize(16777215, 60));
|
||
|
m_getNoticeFrame->setFrameShape(QFrame::Box);
|
||
|
|
||
|
QHBoxLayout *mGetNoticeLayout = new QHBoxLayout(m_getNoticeFrame);
|
||
|
mGetNoticeLayout->setContentsMargins(16,0,16,0);
|
||
|
|
||
|
m_getNoticeLabel = new QLabel(m_getNoticeFrame);
|
||
|
m_getNoticeLabel->setFixedWidth(550);
|
||
|
m_enableSwitchBtn = new KSwitchButton(m_getNoticeFrame);
|
||
|
m_enableSwitchBtn->setObjectName("getnoticeinfo");
|
||
|
|
||
|
mGetNoticeLayout->addWidget(m_getNoticeLabel,Qt::AlignLeft);
|
||
|
mGetNoticeLayout->addStretch();
|
||
|
mGetNoticeLayout->addWidget(m_enableSwitchBtn);
|
||
|
|
||
|
m_noticeAppFrame = new QFrame(Noticewidget);
|
||
|
m_noticeAppFrame->setMinimumSize(QSize(550, 0));
|
||
|
m_noticeAppFrame->setMaximumSize(QSize(16777215, 16777215));
|
||
|
m_noticeAppFrame->setFrameShape(QFrame::Box);
|
||
|
|
||
|
m_applistverticalLayout = new QVBoxLayout(m_noticeAppFrame);
|
||
|
m_applistverticalLayout->setContentsMargins(0,0,0,0);
|
||
|
m_applistverticalLayout->setSpacing(0);
|
||
|
|
||
|
NoticeLayout->addWidget(m_noticeLabel);
|
||
|
NoticeLayout->addWidget(m_getNoticeFrame);
|
||
|
NoticeLayout->addWidget(m_noticeAppFrame);
|
||
|
|
||
|
if (1) {
|
||
|
mverticalLayout->addWidget(distrubFrame);
|
||
|
mverticalLayout->addSpacing(8);
|
||
|
mverticalLayout->addWidget(notFazeFrame);
|
||
|
mverticalLayout->addSpacing(32);
|
||
|
} else {
|
||
|
distrubFrame->hide();
|
||
|
notFazeFrame->hide();
|
||
|
}
|
||
|
mverticalLayout->addWidget(Noticewidget);
|
||
|
mverticalLayout->addStretch();
|
||
|
|
||
|
}
|
||
|
|
||
|
void Notice::initNotFaze(QFrame *frame)
|
||
|
{
|
||
|
frame->setMinimumSize(QSize(550, 0));
|
||
|
frame->setMaximumSize(QSize(16777215, 16777215));
|
||
|
frame->setFrameShape(QFrame::Box);
|
||
|
|
||
|
QVBoxLayout *notFazeLyt = new QVBoxLayout(frame);
|
||
|
notFazeLyt->setContentsMargins(0, 0, 0, 0);
|
||
|
notFazeLyt->setSpacing(0);
|
||
|
|
||
|
QFrame *line_1 = NoticeMenu::setLine();
|
||
|
QFrame *line_2 = NoticeMenu::setLine();
|
||
|
QFrame *line_3 = NoticeMenu::setLine();
|
||
|
|
||
|
QFrame *autoOpenFrame = new QFrame(frame);
|
||
|
autoOpenFrame->setMinimumSize(550, 60);
|
||
|
autoOpenFrame->setMaximumSize(16777215, 60);
|
||
|
QHBoxLayout *autoLyt = new QHBoxLayout(autoOpenFrame);
|
||
|
autoLyt->setContentsMargins(16, 0, 16, 0);
|
||
|
QLabel *autoOpenLabel = new QLabel(tr("Automatically turn on"), autoOpenFrame);
|
||
|
m_openTimeHCombox = new QComboBox(autoOpenFrame);
|
||
|
m_openTimeHCombox->setObjectName("opentimehour");
|
||
|
m_openTimeHCombox->setFixedWidth(64);
|
||
|
m_openTimeMCombox = new QComboBox(autoOpenFrame);
|
||
|
m_openTimeMCombox->setObjectName("opentimeminute");
|
||
|
m_openTimeMCombox->setFixedWidth(64);
|
||
|
m_closeTimeHCombox = new QComboBox(autoOpenFrame);
|
||
|
m_closeTimeHCombox->setObjectName("closetimehour");
|
||
|
m_closeTimeHCombox->setFixedWidth(64);
|
||
|
m_closeTimeMCombox = new QComboBox(autoOpenFrame);
|
||
|
m_closeTimeMCombox->setObjectName("closetimeminute");
|
||
|
m_closeTimeMCombox->setFixedWidth(64);
|
||
|
for (int i = 0; i < 24; i++) {
|
||
|
m_openTimeHCombox->addItem(QStringLiteral("%1").arg(i, 2, 10, QLatin1Char('0')));
|
||
|
m_closeTimeHCombox->addItem(QStringLiteral("%1").arg(i, 2, 10, QLatin1Char('0')));
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 60; i++) {
|
||
|
m_openTimeMCombox->addItem(QStringLiteral("%1").arg(i, 2, 10, QLatin1Char('0')));
|
||
|
m_closeTimeMCombox->addItem(QStringLiteral("%1").arg(i, 2, 10, QLatin1Char('0')));
|
||
|
}
|
||
|
|
||
|
QLabel * label_1 = new QLabel(autoOpenFrame);
|
||
|
label_1->setFixedWidth(20);
|
||
|
label_1->setText(tr("to"));
|
||
|
QLabel *label_2 = new QLabel(autoOpenFrame);
|
||
|
label_2->setFixedWidth(4);
|
||
|
label_2->setText(":");
|
||
|
QLabel *label_3 = new QLabel(autoOpenFrame);
|
||
|
label_3->setFixedWidth(4);
|
||
|
label_3->setText(":");
|
||
|
m_autoOpenSwitchBtn = new KSwitchButton(autoOpenFrame);
|
||
|
m_autoOpenSwitchBtn->setObjectName("autoopen");
|
||
|
|
||
|
autoLyt->addWidget(autoOpenLabel);
|
||
|
autoLyt->addStretch();
|
||
|
autoLyt->addWidget(m_openTimeHCombox);
|
||
|
autoLyt->addWidget(label_2);
|
||
|
autoLyt->addWidget(m_openTimeMCombox);
|
||
|
autoLyt->addWidget(label_1);
|
||
|
autoLyt->addWidget(m_closeTimeHCombox);
|
||
|
autoLyt->addWidget(label_3);
|
||
|
autoLyt->addWidget(m_closeTimeMCombox);
|
||
|
autoLyt->addSpacing(24);
|
||
|
autoLyt->addWidget(m_autoOpenSwitchBtn);
|
||
|
|
||
|
QFrame *multiScreenFrame = new QFrame(frame);
|
||
|
m_multiScreenSwitchBtn= new KSwitchButton();
|
||
|
m_multiScreenSwitchBtn->setObjectName("multiscreen");
|
||
|
setFrame(multiScreenFrame, m_multiScreenSwitchBtn, tr("Automatically turn on when multiple screens are connected"));
|
||
|
|
||
|
QFrame *fullScreenFrame = new QFrame(frame);
|
||
|
m_fullScreenSwitchBtn= new KSwitchButton();
|
||
|
m_fullScreenSwitchBtn->setObjectName("fullscreen");
|
||
|
setFrame(fullScreenFrame, m_fullScreenSwitchBtn, tr("Automatically open in full screen mode"));
|
||
|
|
||
|
QFrame *allowAlarmrRemindersFrame = new QFrame(frame);
|
||
|
m_allowAlarmrSwitchBtn= new KSwitchButton();
|
||
|
m_allowAlarmrSwitchBtn->setObjectName("allowAlarmr");
|
||
|
setFrame(allowAlarmrRemindersFrame, m_allowAlarmrSwitchBtn, tr("Allow automatic alarm reminders in Do Not Disturb mode"));
|
||
|
|
||
|
notFazeLyt->addWidget(autoOpenFrame);
|
||
|
notFazeLyt->addWidget(line_1);
|
||
|
notFazeLyt->addWidget(multiScreenFrame);
|
||
|
notFazeLyt->addWidget(line_2);
|
||
|
notFazeLyt->addWidget(fullScreenFrame);
|
||
|
notFazeLyt->addWidget(line_3);
|
||
|
notFazeLyt->addWidget(allowAlarmrRemindersFrame);
|
||
|
}
|
||
|
|
||
|
void Notice::setFrame(QFrame *frame, KSwitchButton *btn, QString str)
|
||
|
{
|
||
|
frame->setMinimumSize(QSize(550, 60));
|
||
|
frame->setMaximumSize(QSize(16777215, 60));
|
||
|
frame->setFrameShape(QFrame::NoFrame);
|
||
|
|
||
|
QHBoxLayout *hLyt = new QHBoxLayout(frame);
|
||
|
hLyt->setContentsMargins(16, 0, 16, 0);
|
||
|
QLabel *label = new QLabel(str, frame);
|
||
|
|
||
|
hLyt->addWidget(label);
|
||
|
hLyt->addStretch();
|
||
|
hLyt->addWidget(btn);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void Notice::initSearchText()
|
||
|
{
|
||
|
m_noticeLabel->setText(tr("Notice Settings"));
|
||
|
//~ contents_path /notice/Get notifications from the app
|
||
|
m_getNoticeLabel->setText(tr("Get notifications from the app"));
|
||
|
}
|
||
|
|
||
|
void Notice::initConnection()
|
||
|
{
|
||
|
if (m_globalSettings) {
|
||
|
connect(m_openTimeHCombox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this, [&](const QString &text){
|
||
|
//Utils::buriedSettings(name(), "open time(hour) when auto turn on do not disturb mode", QString("settings"), text);
|
||
|
m_globalSettings->setScheduleTurnOnDNDTime(QTime().fromString(QString("%1%2%3").arg(text).arg(":").arg(m_openTimeMCombox->currentText()), "hh:mm"));
|
||
|
});
|
||
|
|
||
|
connect(m_openTimeMCombox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this, [&](const QString &text){
|
||
|
//Utils::buriedSettings(name(), "open time(minute) when auto turn on do not disturb mode", QString("settings"), m_openTimeMCombox->currentText());
|
||
|
m_globalSettings->setScheduleTurnOnDNDTime(QTime().fromString(QString("%1%2%3").arg(text).arg(":").arg(m_openTimeHCombox->currentText()), "mm:hh"));
|
||
|
});
|
||
|
|
||
|
connect(m_closeTimeHCombox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this, [&](const QString &text){
|
||
|
//Utils::buriedSettings(name(), "close time(hour) when auto turn on do not disturb mode", QString("settings"), m_closeTimeMCombox->currentText());
|
||
|
m_globalSettings->setScheduleTurnOffDNDTime(QTime().fromString(QString("%1%2%3").arg(text).arg(":").arg(m_closeTimeMCombox->currentText()), "hh:mm"));
|
||
|
});
|
||
|
|
||
|
connect(m_closeTimeMCombox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged), this, [&](const QString &text){
|
||
|
//Utils::buriedSettings(name(), "close time(minute) when auto turn on do not disturb mode", QString("settings"), m_closeTimeMCombox->currentText());
|
||
|
m_globalSettings->setScheduleTurnOffDNDTime(QTime().fromString(QString("%1%2%3").arg(text).arg(":").arg(m_closeTimeHCombox->currentText()), "mm:hh"));
|
||
|
});
|
||
|
|
||
|
connect(m_autoOpenSwitchBtn, &KSwitchButton::stateChanged, [&](bool state) {
|
||
|
//Utils::buriedSettings(name(), "whether auto turn on do not disturb mode", QString("settings"), state ? "true" : "false");
|
||
|
m_globalSettings->setScheduleTurnOnDND(state);
|
||
|
setComBoxStatus(state);
|
||
|
});
|
||
|
connect(m_multiScreenSwitchBtn, &KSwitchButton::stateChanged, [&](bool state) {
|
||
|
//Utils::buriedSettings(name(), "whether auto turn on do not disturb mode", QString("settings"), state ? "true" : "false");
|
||
|
m_globalSettings->setDNDWhileMultiScreen(state);
|
||
|
});
|
||
|
connect(m_fullScreenSwitchBtn, &KSwitchButton::stateChanged, [&](bool state) {
|
||
|
//Utils::buriedSettings(name(), "whether auto turn on do not disturb mode", QString("settings"), state ? "true" : "false");
|
||
|
m_globalSettings->setDNDWhileFullScreen(state);
|
||
|
});
|
||
|
connect(m_allowAlarmrSwitchBtn, &KSwitchButton::stateChanged, [&](bool state) {
|
||
|
//Utils::buriedSettings(name(), "whether auto turn on do not disturb mode", QString("settings"), state ? "true" : "false");
|
||
|
m_globalSettings->setNotifyAlarmWhileDND(state);
|
||
|
});
|
||
|
connect(m_enableSwitchBtn, &KSwitchButton::stateChanged, [&](bool state){
|
||
|
//Utils::buriedSettings(name(), "whether to get the notification from the app", QString("settings"), state ? "true" : "false");
|
||
|
m_globalSettings->blockSignals(true);
|
||
|
m_globalSettings->setReceiveNotificationsFromApps(state);
|
||
|
m_globalSettings->blockSignals(false);
|
||
|
setHiddenNoticeApp(state);
|
||
|
});
|
||
|
|
||
|
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::scheduleTurnOnDNDChanged, this, [&](bool state) {
|
||
|
m_autoOpenSwitchBtn->blockSignals(true);
|
||
|
m_autoOpenSwitchBtn->setChecked(state);
|
||
|
m_autoOpenSwitchBtn->blockSignals(false);
|
||
|
setComBoxStatus(state);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::scheduleTurnOnDNDTimeChanged, this, [&](QTime time) {
|
||
|
m_openTimeHCombox->blockSignals(true);
|
||
|
m_openTimeHCombox->setCurrentText(time.toString("hh"));
|
||
|
m_openTimeHCombox->blockSignals(false);
|
||
|
|
||
|
m_openTimeMCombox->blockSignals(true);
|
||
|
m_openTimeMCombox->setCurrentText(time.toString("mm"));
|
||
|
m_openTimeMCombox->blockSignals(false);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::scheduleTurnOffDNDTimeChanged, this, [&](QTime time) {
|
||
|
m_closeTimeHCombox->blockSignals(true);
|
||
|
m_closeTimeHCombox->setCurrentText(time.toString("hh"));
|
||
|
m_closeTimeHCombox->blockSignals(false);
|
||
|
|
||
|
m_closeTimeMCombox->blockSignals(true);
|
||
|
m_closeTimeMCombox->setCurrentText(time.toString("mm"));
|
||
|
m_closeTimeMCombox->blockSignals(false);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::DNDWhileMultiScreenChanged, this, [&](bool state) {
|
||
|
m_multiScreenSwitchBtn->blockSignals(true);
|
||
|
m_multiScreenSwitchBtn->setChecked(state);
|
||
|
m_multiScreenSwitchBtn->blockSignals(false);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::DNDWhileFullScreenChanged, this, [&](bool state) {
|
||
|
m_fullScreenSwitchBtn->blockSignals(true);
|
||
|
m_fullScreenSwitchBtn->setChecked(state);
|
||
|
m_fullScreenSwitchBtn->blockSignals(false);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::notifyAlarmWhileDNDChanged, this, [&](bool state) {
|
||
|
m_allowAlarmrSwitchBtn->blockSignals(true);
|
||
|
m_allowAlarmrSwitchBtn->setChecked(state);
|
||
|
m_allowAlarmrSwitchBtn->blockSignals(false);
|
||
|
});
|
||
|
connect(m_globalSettings, &UkuiNotification::NotificationGlobalSettings::receiveNotificationsFromAppsChanged, this, [&](bool state) {
|
||
|
m_enableSwitchBtn->blockSignals(true);
|
||
|
m_enableSwitchBtn->setChecked(state);
|
||
|
m_enableSwitchBtn->blockSignals(false);
|
||
|
setHiddenNoticeApp(state);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void Notice::initNoticeStatus()
|
||
|
{
|
||
|
if (m_globalSettings) {
|
||
|
m_autoOpenSwitchBtn->blockSignals(true);
|
||
|
m_autoOpenSwitchBtn->setChecked(m_globalSettings->scheduleTurnOnDND());
|
||
|
setComBoxStatus(m_autoOpenSwitchBtn->isChecked());
|
||
|
m_autoOpenSwitchBtn->blockSignals(false);
|
||
|
|
||
|
QTime openTime = m_globalSettings->scheduleTurnOnDNDTime();
|
||
|
m_openTimeHCombox->blockSignals(true);
|
||
|
m_openTimeHCombox->setCurrentText(openTime.toString("hh"));
|
||
|
m_openTimeHCombox->blockSignals(false);
|
||
|
m_openTimeMCombox->blockSignals(true);
|
||
|
m_openTimeMCombox->setCurrentText(openTime.toString("mm"));
|
||
|
m_openTimeMCombox->blockSignals(false);
|
||
|
|
||
|
QTime closeTime = m_globalSettings->scheduleTurnOffDNDTime();
|
||
|
m_closeTimeHCombox->blockSignals(true);
|
||
|
m_closeTimeHCombox->setCurrentText(closeTime.toString("hh"));
|
||
|
m_closeTimeHCombox->blockSignals(false);
|
||
|
m_closeTimeMCombox->blockSignals(true);
|
||
|
m_closeTimeMCombox->setCurrentText(closeTime.toString("mm"));
|
||
|
m_closeTimeMCombox->blockSignals(false);
|
||
|
|
||
|
m_multiScreenSwitchBtn->blockSignals(true);
|
||
|
m_multiScreenSwitchBtn->setChecked(m_globalSettings->DNDWhileMultiScreen());
|
||
|
m_multiScreenSwitchBtn->blockSignals(false);
|
||
|
m_fullScreenSwitchBtn->blockSignals(true);
|
||
|
m_fullScreenSwitchBtn->setChecked(m_globalSettings->DNDWhileFullScreen());
|
||
|
m_fullScreenSwitchBtn->blockSignals(false);
|
||
|
m_allowAlarmrSwitchBtn->blockSignals(true);
|
||
|
m_allowAlarmrSwitchBtn->setChecked(m_globalSettings->notifyAlarmWhileDND());
|
||
|
m_allowAlarmrSwitchBtn->blockSignals(false);
|
||
|
m_enableSwitchBtn->blockSignals(true);
|
||
|
m_enableSwitchBtn->setChecked(m_globalSettings->receiveNotificationsFromApps());
|
||
|
m_enableSwitchBtn->blockSignals(false);
|
||
|
}
|
||
|
|
||
|
setHiddenNoticeApp(m_enableSwitchBtn->isChecked());
|
||
|
}
|
||
|
|
||
|
void Notice::initListUI()
|
||
|
{
|
||
|
UkuiNotification::ApplicationsSettingsHash &appDataHash = UkuiNotification::ApplicationsSettings::self()->getAllApplicationsSettings();
|
||
|
for (auto &key : appDataHash.keys()) {
|
||
|
initItemUi(key, appDataHash[key]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Notice::initItemUi(const QString &desktopPath, const UkuiNotification::SingleApplicationSettings &settings)
|
||
|
{
|
||
|
QString localName = m_appInfo->getInfo(desktopPath, UkuiSearch::ApplicationProperty::LocalName).toString();
|
||
|
QString iconName = m_appInfo->getInfo(desktopPath, UkuiSearch::ApplicationProperty::Icon).toString();
|
||
|
QString fileName = desktopPath.left(desktopPath.indexOf(QLatin1Char('.')));
|
||
|
|
||
|
QFrame *baseWidget = new QFrame(m_noticeAppFrame);
|
||
|
baseWidget->setMinimumWidth(550);
|
||
|
baseWidget->setMaximumWidth(16777215);
|
||
|
baseWidget->setFixedHeight(60);
|
||
|
baseWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||
|
baseWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||
|
|
||
|
QLabel *iconLabel = new QLabel(baseWidget);
|
||
|
iconLabel->setFixedSize(32, 32);
|
||
|
|
||
|
if (fileName == "ukui-flash-disk")
|
||
|
iconName = "drive-removable-media-usb";
|
||
|
|
||
|
setAppIcon(iconLabel, iconName);
|
||
|
connect(m_themeSetting, &QGSettings::changed, [&](const QString &key){
|
||
|
if (key == "iconThemeName")
|
||
|
setAppIcon(iconLabel, iconName);
|
||
|
});
|
||
|
|
||
|
QHBoxLayout *devHorLayout = new QHBoxLayout(baseWidget);
|
||
|
devHorLayout->setSpacing(8);
|
||
|
devHorLayout->setContentsMargins(16, 0, 16, 0);
|
||
|
|
||
|
QLabel *nameLabel = new QLabel(baseWidget);
|
||
|
nameLabel->setText(localName);
|
||
|
|
||
|
ukToolButton *setBtn = new ukToolButton(baseWidget);
|
||
|
setBtn->setProperty("useButtonPalette", true);
|
||
|
setBtn->setPopupMode(QToolButton::InstantPopup);
|
||
|
setBtn->setFixedSize(QSize(36, 36));
|
||
|
setBtn->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
|
||
|
|
||
|
NoticeMenu *menu = new NoticeMenu(setBtn);
|
||
|
setBtn->setMenu(menu);
|
||
|
|
||
|
KSwitchButton *appSwitch = new KSwitchButton(baseWidget);
|
||
|
|
||
|
devHorLayout->addWidget(iconLabel);
|
||
|
devHorLayout->addWidget(nameLabel);
|
||
|
devHorLayout->addStretch();
|
||
|
devHorLayout->addWidget(setBtn);
|
||
|
devHorLayout->addWidget(appSwitch);
|
||
|
|
||
|
m_applistverticalLayout->addWidget(baseWidget);
|
||
|
if (m_applistverticalLayout->count() >= 2) {
|
||
|
QFrame *line = new QFrame(m_pluginWidget);
|
||
|
line->setMinimumSize(QSize(0, 1));
|
||
|
line->setMaximumSize(QSize(16777215, 1));
|
||
|
line->setLineWidth(0);
|
||
|
line->setFrameShape(QFrame::HLine);
|
||
|
line->setFrameShadow(QFrame::Sunken);
|
||
|
m_applistverticalLayout->insertWidget(m_applistverticalLayout->count() - 1, line);
|
||
|
}
|
||
|
|
||
|
|
||
|
appSwitch->blockSignals(true);
|
||
|
appSwitch->setChecked(settings.allowNotify());
|
||
|
appSwitch->blockSignals(false);
|
||
|
|
||
|
menu->blockSignals(true);
|
||
|
menu->initStaus(settings);
|
||
|
menu->blockSignals(false);
|
||
|
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::allowNotifyChanged, [=](bool state) {
|
||
|
appSwitch->blockSignals(true);
|
||
|
appSwitch->setChecked(state);
|
||
|
appSwitch->blockSignals(false);
|
||
|
});
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::allowSoundChanged, [=](bool state) {
|
||
|
menu->blockSignals(true);
|
||
|
menu->setVoiceEnable(state);
|
||
|
menu->blockSignals(false);
|
||
|
});
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::showContentOnLockScreenChanged, [=](bool state) {
|
||
|
menu->blockSignals(true);
|
||
|
menu->setDetailShowOnLockScreenEnable(state);
|
||
|
menu->blockSignals(false);
|
||
|
});
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::showNotificationOnLockScreenChanged, [=](bool state) {
|
||
|
menu->blockSignals(true);
|
||
|
menu->setShowOnLockScreenEnable(state);
|
||
|
menu->blockSignals(false);
|
||
|
});
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::popupStyleChanged, [=](UkuiNotification::SettingsProperty::Property style) {
|
||
|
menu->blockSignals(true);
|
||
|
menu->setShowOnLockScreenEnable(style);
|
||
|
menu->blockSignals(false);
|
||
|
});
|
||
|
connect(&settings, &UkuiNotification::SingleApplicationSettings::uninstalled, [=]() {
|
||
|
baseWidget->hide();
|
||
|
});
|
||
|
|
||
|
|
||
|
connect(menu, &NoticeMenu::voiceSignals, [=](bool checked) {
|
||
|
//Common::buriedSettings(name(), "whether prompt sound during notification", QString("settings"), checked ? "true" : "false");
|
||
|
UkuiNotification::ApplicationsSettings::self()->setAppSetting(desktopPath, UkuiNotification::SettingsProperty::AllowSound, checked);
|
||
|
});
|
||
|
|
||
|
connect(menu, &NoticeMenu::detailSignals, [=](bool checked) {
|
||
|
//Common::buriedSettings(name(), "whether to show the message content in the lock screen interface", QString("settings"), checked ? "true" : "false");
|
||
|
UkuiNotification::ApplicationsSettings::self()->setAppSetting(desktopPath, UkuiNotification::SettingsProperty::ShowContentOnLockScreen, checked);
|
||
|
});
|
||
|
|
||
|
connect(menu, &NoticeMenu::showSignals, [=](bool checked) {
|
||
|
//Common::buriedSettings(name(), "whether to show the notice in the lock screen interface", QString("settings"), checked ? "true" : "false");
|
||
|
UkuiNotification::ApplicationsSettings::self()->setAppSetting(desktopPath, UkuiNotification::SettingsProperty::ShowNotificationOnLockScreen, checked);
|
||
|
});
|
||
|
|
||
|
connect(menu, &NoticeMenu::styleBtnSignals, [=](int id) {
|
||
|
QString str("mutative");
|
||
|
UkuiNotification::SettingsProperty::Property style = UkuiNotification::SettingsProperty::TransientPopup;
|
||
|
if (id == 0) {
|
||
|
str = "mutative";
|
||
|
style = UkuiNotification::SettingsProperty::TransientPopup;
|
||
|
} else if (id == 1) {
|
||
|
str = "always";
|
||
|
style = UkuiNotification::SettingsProperty::ResidentPopup;
|
||
|
} else if (id == 2) {
|
||
|
str = "none";
|
||
|
style = UkuiNotification::SettingsProperty::NoPopup;
|
||
|
}
|
||
|
//Common::buriedSettings(name(), "set notice style", QString("settings"), str);
|
||
|
UkuiNotification::ApplicationsSettings::self()->setAppSetting(desktopPath, UkuiNotification::SettingsProperty::PopupStyle, style);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
void Notice::setAppIcon(QLabel *iconlabel, const QString &icon)
|
||
|
{
|
||
|
QFileInfo iconfile(QString("/usr/share/pixmaps/"+ icon + ".png"));
|
||
|
QPixmap pixmap;
|
||
|
QIcon currenticon = QIcon::fromTheme(icon);
|
||
|
if (!currenticon.isNull()) {
|
||
|
pixmap = currenticon.pixmap(QSize(32, 32));
|
||
|
} else if (iconfile.exists()) {
|
||
|
pixmap = QPixmap(iconfile.filePath()).scaled(32, 32);
|
||
|
} else {
|
||
|
pixmap = QPixmap(QString(":/img/plugins/autoboot/desktop.png"));
|
||
|
}
|
||
|
iconlabel->setPixmap(pixmap);
|
||
|
}
|
||
|
|
||
|
void Notice::setHiddenNoticeApp(bool status)
|
||
|
{
|
||
|
m_noticeAppFrame->setVisible(status);
|
||
|
}
|
||
|
|
||
|
void Notice::setComBoxStatus(bool status)
|
||
|
{
|
||
|
m_openTimeHCombox->setEnabled(status);
|
||
|
m_closeTimeHCombox->setEnabled(status);
|
||
|
m_openTimeMCombox->setEnabled(status);
|
||
|
m_closeTimeMCombox->setEnabled(status);
|
||
|
}
|
||
|
|
||
|
void ukToolButton::paintEvent(QPaintEvent *event)
|
||
|
{
|
||
|
QPalette paltte;
|
||
|
paltte.setColor(QPalette::Button, paltte.base().color());
|
||
|
this->setPalette(paltte);
|
||
|
QToolButton::paintEvent(event);
|
||
|
}
|