make it possible to embed the settings dialog, enable snore-settings to modifiy local settings of other applications
This commit is contained in:
parent
69819fb635
commit
aa331a7e98
|
@ -28,7 +28,7 @@
|
|||
using namespace Snore;
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
QWidget(parent),
|
||||
ui(new Ui::SettingsDialog),
|
||||
m_app(new Application("SnoreSettings", Icon(":/root/snore.png"))),
|
||||
m_alert(new Alert("Test", Icon(":/root/snore.png")))
|
||||
|
@ -67,7 +67,7 @@ void SettingsDialog::load()
|
|||
ui->primaryBackendComboBox->clear();
|
||||
QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::BACKEND);
|
||||
ui->primaryBackendComboBox->addItems(list);
|
||||
ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(SnoreCore::instance().primaryNotificationBackend()));
|
||||
ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(SnoreCore::instance().value("PrimaryBackend", LOCAL_SETTING).toString()));
|
||||
for (auto widget : m_tabs) {
|
||||
widget->loadSettings();
|
||||
}
|
||||
|
@ -86,15 +86,12 @@ void SettingsDialog::save()
|
|||
void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
||||
{
|
||||
switch (ui->buttonBox->buttonRole(button)) {
|
||||
case QDialogButtonBox::AcceptRole:
|
||||
case QDialogButtonBox::ApplyRole:
|
||||
save();
|
||||
break;
|
||||
case QDialogButtonBox::ResetRole:
|
||||
load();
|
||||
break;
|
||||
case QDialogButtonBox::RejectRole:
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "unhandled role" << button->text();
|
||||
}
|
||||
|
@ -103,5 +100,19 @@ void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|||
void SettingsDialog::show()
|
||||
{
|
||||
load();
|
||||
QDialog::show();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void SettingsDialog::accept()
|
||||
{
|
||||
hide();
|
||||
save();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void SettingsDialog::reject()
|
||||
{
|
||||
hide();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class SettingsDialog;
|
|||
|
||||
namespace Snore
|
||||
{
|
||||
class SNORE_EXPORT SettingsDialog : public QDialog
|
||||
class SNORE_EXPORT SettingsDialog : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -48,7 +48,14 @@ public:
|
|||
explicit SettingsDialog(QWidget *parent = 0);
|
||||
~SettingsDialog();
|
||||
|
||||
|
||||
public slots:
|
||||
void show();
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsDialog</class>
|
||||
<widget class="QDialog" name="SettingsDialog">
|
||||
<widget class="QWidget" name="SettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
@ -20,12 +20,18 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="tabShape">
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Page</string>
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
|
|
|
@ -191,6 +191,9 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
|
|||
list.append(widget);
|
||||
}
|
||||
}
|
||||
qSort(list.begin(),list.end(),[](PluginSettingsWidget *a,PluginSettingsWidget *b){
|
||||
return a->name() < b->name();
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -164,6 +164,22 @@ void SnoreCorePrivate::syncSettings()
|
|||
}
|
||||
}
|
||||
|
||||
QStringList SnoreCorePrivate::knownClients(){
|
||||
QStringList out;
|
||||
m_settings->beginGroup(versionSchema());
|
||||
m_settings->beginGroup("LocalSettings");
|
||||
out = m_settings->childGroups();
|
||||
m_settings->endGroup();
|
||||
m_settings->endGroup();
|
||||
return out;
|
||||
}
|
||||
|
||||
void SnoreCorePrivate::setLocalSttingsPrefix(const QString &prefix)
|
||||
{
|
||||
m_localSettingsPrefix = prefix;
|
||||
syncSettings();
|
||||
}
|
||||
|
||||
void SnoreCorePrivate::registerMetaTypes()
|
||||
{
|
||||
qRegisterMetaType<Notification>();
|
||||
|
|
|
@ -75,12 +75,17 @@ public:
|
|||
QString normalizeKey(const QString &key, SettingsType type) const
|
||||
{
|
||||
if (type == LOCAL_SETTING) {
|
||||
return QString("%1/LocalSettings/%2.%3/%4").arg(versionSchema(), qApp->organizationName(), qApp->applicationName(), key);
|
||||
return QString("%1/LocalSettings/%2/%3").arg(versionSchema(),m_localSettingsPrefix, key);
|
||||
} else {
|
||||
return QString("%1/%2").arg(versionSchema(), key);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: rename
|
||||
QStringList knownClients();
|
||||
|
||||
void setLocalSttingsPrefix(const QString &prefix);
|
||||
|
||||
signals:
|
||||
void applicationRegistered(const Snore::Application &);
|
||||
void applicationDeregistered(const Snore::Application &);
|
||||
|
@ -103,6 +108,8 @@ private:
|
|||
|
||||
Application m_defaultApp;
|
||||
|
||||
QString m_localSettingsPrefix = QString("%1.%2").arg(qApp->organizationName(), qApp->applicationName());
|
||||
|
||||
QSettings *m_settings;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
ecm_add_app_icon(SNORENOTIFY_SETTINGS_DEPS ICONS ${PROJECT_SOURCE_DIR}/data/128-apps-snore.png)
|
||||
|
||||
add_executable( snoresettings WIN32 main.cpp ${UI} ${SNORENOTIFY_SETTINGS_DEPS})
|
||||
qt5_wrap_ui(UI settingswindow.ui)
|
||||
|
||||
add_executable( snoresettings WIN32 main.cpp settingswindow.cpp ${UI} ${SNORENOTIFY_SETTINGS_DEPS})
|
||||
target_link_libraries( snoresettings Snore::Libsnore )
|
||||
install(TARGETS snoresettings ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "core/settingsdialog.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/version.h"
|
||||
#include "settingswindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
@ -13,13 +13,9 @@ int main(int argc, char *argv[])
|
|||
app.setOrganizationName("SnoreNotify");
|
||||
app.setApplicationVersion(Snore::Version::version());
|
||||
|
||||
Snore::SnoreCore &snore = Snore::SnoreCore::instance();
|
||||
snore.loadPlugins(Snore::SnorePlugin::ALL);
|
||||
|
||||
Snore::SettingsDialog diag;
|
||||
diag.setWindowTitle("SnoreSettings");
|
||||
diag.show();
|
||||
QObject::connect(&diag, &Snore::SettingsDialog::finished, &app, &QApplication::quit);
|
||||
Snore::SnoreCore::instance().loadPlugins(Snore::SnorePlugin::ALL);
|
||||
SettingsWindow window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "settingswindow.h"
|
||||
#include "ui_settingswindow.h"
|
||||
|
||||
#include "snore.h"
|
||||
#include "snore_p.h"
|
||||
#include "settingsdialog.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SettingsWindow::SettingsWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::SettingsWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->widget->show();
|
||||
connect(ui->widget, &Snore::SettingsDialog::finished, qApp, &QApplication::quit);
|
||||
|
||||
QStringList list = SnoreCorePrivate::instance()->knownClients();
|
||||
list.removeAll(QString("%1.%2").arg(qApp->organizationName(), qApp->applicationName()));
|
||||
ui->comboBox->addItems(list);
|
||||
}
|
||||
|
||||
SettingsWindow::~SettingsWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SettingsWindow::on_comboBox_currentIndexChanged(const QString &arg1)
|
||||
{
|
||||
SnoreCorePrivate::instance()->setLocalSttingsPrefix(arg1);
|
||||
ui->widget->show();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef SETTINGSWINDOW_H
|
||||
#define SETTINGSWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class SettingsWindow;
|
||||
}
|
||||
|
||||
class SettingsWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsWindow(QWidget *parent = 0);
|
||||
~SettingsWindow();
|
||||
|
||||
private slots:
|
||||
void on_comboBox_currentIndexChanged(const QString &arg1);
|
||||
|
||||
private:
|
||||
Ui::SettingsWindow *ui;
|
||||
};
|
||||
|
||||
#endif // SETTINGSWINDOW_H
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsWindow</class>
|
||||
<widget class="QMainWindow" name="SettingsWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Application:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Snore::SettingsDialog" name="widget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Snore::SettingsDialog</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">core/settingsdialog.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue