use singleton for snorecore
This commit is contained in:
parent
2713e36f90
commit
e9e9d57dba
|
@ -61,12 +61,12 @@ bool SnorePlugin::isInitialized() const
|
|||
|
||||
SnoreCore *SnorePlugin::snore()
|
||||
{
|
||||
return SnoreCorePrivate::snoreInstance();
|
||||
return &SnoreCore::instance();
|
||||
}
|
||||
|
||||
const SnoreCore *SnorePlugin::snore() const
|
||||
{
|
||||
return SnoreCorePrivate::snoreInstance();
|
||||
return &SnoreCore::instance();
|
||||
}
|
||||
|
||||
QVariant SnorePlugin::value(const QString &key) const
|
||||
|
|
|
@ -48,8 +48,8 @@ public:
|
|||
virtual bool initialize();
|
||||
virtual bool deinitialize();
|
||||
bool isInitialized() const;
|
||||
SnoreCore *snore();
|
||||
const SnoreCore *snore() const;
|
||||
LIBSNORE_DEPRECATED SnoreCore *snore();
|
||||
LIBSNORE_DEPRECATED const SnoreCore *snore() const;
|
||||
|
||||
const QString &name() const;
|
||||
PluginTypes type() const;
|
||||
|
|
|
@ -27,10 +27,9 @@
|
|||
|
||||
using namespace Snore;
|
||||
|
||||
SettingsDialog::SettingsDialog(SnoreCore *snore, QWidget *parent) :
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SettingsDialog),
|
||||
m_snore(snore),
|
||||
m_app(new Application("SnoreSettings", Icon(":/root/snore.png"))),
|
||||
m_alert(new Alert("Test", Icon(":/root/snore.png")))
|
||||
{
|
||||
|
@ -38,7 +37,7 @@ SettingsDialog::SettingsDialog(SnoreCore *snore, QWidget *parent) :
|
|||
|
||||
m_app->addAlert(*m_alert);
|
||||
|
||||
for (auto widget : snore->settingWidgets()) {
|
||||
for (auto widget : SnoreCore::instance().settingWidgets()) {
|
||||
ui->tabWidget->addTab(widget, widget->name());
|
||||
m_tabs.append(widget);
|
||||
}
|
||||
|
@ -52,24 +51,24 @@ SettingsDialog::~SettingsDialog()
|
|||
|
||||
void Snore::SettingsDialog::on_pushButton_clicked()
|
||||
{
|
||||
if (!m_snore->aplications().contains(m_app->name())) {
|
||||
m_snore->registerApplication(*m_app);
|
||||
if (!SnoreCore::instance().aplications().contains(m_app->name())) {
|
||||
SnoreCore::instance().registerApplication(*m_app);
|
||||
}
|
||||
Notification noti(*m_app, *m_alert, "Hello World",
|
||||
"<i>This is Snore</i><br>"
|
||||
"<a href=\"https://github.com/TheOneRing/Snorenotify\">Project Website</a><br>",
|
||||
Icon(":/root/snore.png"));
|
||||
noti.addAction(Action(1, "Test Action"));
|
||||
m_snore->broadcastNotification(noti);
|
||||
SnoreCore::instance().broadcastNotification(noti);
|
||||
}
|
||||
|
||||
void SettingsDialog::load()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "loading";
|
||||
ui->primaryBackendComboBox->clear();
|
||||
QStringList list = m_snore->pluginNames(SnorePlugin::BACKEND);
|
||||
QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::BACKEND);
|
||||
ui->primaryBackendComboBox->addItems(list);
|
||||
ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(m_snore->primaryNotificationBackend()));
|
||||
ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(SnoreCore::instance().primaryNotificationBackend()));
|
||||
for (auto widget : m_tabs) {
|
||||
widget->loadSettings();
|
||||
}
|
||||
|
@ -78,7 +77,7 @@ void SettingsDialog::load()
|
|||
void SettingsDialog::save()
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << "saving";
|
||||
m_snore->d()->setBackendIfAvailible(ui->primaryBackendComboBox->currentText());
|
||||
SnoreCore::instance().d()->setBackendIfAvailible(ui->primaryBackendComboBox->currentText());
|
||||
for (auto w : m_tabs) {
|
||||
w->saveSettings();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class SNORE_EXPORT SettingsDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsDialog(SnoreCore *snore, QWidget *parent = 0);
|
||||
explicit SettingsDialog(QWidget *parent = 0);
|
||||
~SettingsDialog();
|
||||
|
||||
private slots:
|
||||
|
@ -57,7 +57,6 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::SettingsDialog *ui;
|
||||
SnoreCore *m_snore;
|
||||
QScopedPointer<Application> m_app;
|
||||
QScopedPointer<Alert> m_alert;
|
||||
QList<Snore::PluginSettingsWidget *> m_tabs;
|
||||
|
|
|
@ -40,6 +40,12 @@ SnoreCore::SnoreCore()
|
|||
d->q_ptr = this;
|
||||
}
|
||||
|
||||
SnoreCore &SnoreCore::instance()
|
||||
{
|
||||
static SnoreCore instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
SnoreCore::~SnoreCore()
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
/**
|
||||
* Creates a Notification Manager SnoreCore
|
||||
*/
|
||||
SnoreCore();
|
||||
static SnoreCore &instance();
|
||||
~SnoreCore();
|
||||
|
||||
/**
|
||||
|
@ -189,6 +189,7 @@ signals:
|
|||
void notificationClosed(Snore::Notification);
|
||||
|
||||
private:
|
||||
SnoreCore();
|
||||
SnoreCorePrivate *d_ptr;
|
||||
|
||||
};
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreCore *SnoreCorePrivate::q_ptr = nullptr;
|
||||
|
||||
SnoreCorePrivate::SnoreCorePrivate():
|
||||
m_defaultApp("SnoreNotify", Icon(":/root/snore.png")),
|
||||
m_settings(new QSettings("Snorenotify", "libsnore", this))
|
||||
|
|
|
@ -63,11 +63,6 @@ public:
|
|||
|
||||
void addSettingsDescription(const QString &key, const QString &help) const;
|
||||
|
||||
static SnoreCore *snoreInstance()
|
||||
{
|
||||
return q_ptr;
|
||||
}
|
||||
|
||||
bool initPrimaryNotificationBackend();
|
||||
|
||||
signals:
|
||||
|
@ -80,8 +75,7 @@ private slots:
|
|||
void slotAboutToQuit();
|
||||
|
||||
private:
|
||||
//TODO: cleanup the static instance
|
||||
static SnoreCore *q_ptr;
|
||||
SnoreCore *q_ptr;
|
||||
|
||||
QHash<QString, Application> m_applications;
|
||||
|
||||
|
|
|
@ -30,16 +30,14 @@ using namespace Snore;
|
|||
SnoreNotify::SnoreNotify()
|
||||
{
|
||||
m_trayIcon = new TrayIcon();
|
||||
m_snore = new SnoreCore();
|
||||
m_snore->loadPlugins(SnorePlugin::ALL);
|
||||
m_trayIcon->initConextMenu(m_snore);
|
||||
SnoreCore::instance().loadPlugins(SnorePlugin::ALL);
|
||||
m_trayIcon->initConextMenu();
|
||||
|
||||
snoreDebug(SNORE_DEBUG) << "Snorenotfiy initialized with" << m_snore->primaryNotificationBackend();
|
||||
snoreDebug(SNORE_DEBUG) << "Snorenotfiy initialized with" << SnoreCore::instance().primaryNotificationBackend();
|
||||
}
|
||||
|
||||
SnoreNotify::~SnoreNotify()
|
||||
{
|
||||
delete m_snore;
|
||||
delete m_trayIcon;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ public:
|
|||
|
||||
private:
|
||||
class TrayIcon *m_trayIcon;
|
||||
Snore::SnoreCore *m_snore;
|
||||
};
|
||||
|
||||
#endif // SNORENOTIFY_H
|
||||
|
|
|
@ -40,11 +40,9 @@ TrayIcon::TrayIcon():
|
|||
m_app.hints().setValue("tray-icon", m_trayIcon);
|
||||
}
|
||||
|
||||
void TrayIcon::initConextMenu(SnoreCore *snore)
|
||||
void TrayIcon::initConextMenu()
|
||||
{
|
||||
m_snore = snore;
|
||||
|
||||
m_settings = new SettingsDialog(snore);
|
||||
m_settings = new SettingsDialog();
|
||||
m_trayIcon->setVisible(true);
|
||||
|
||||
m_trayMenu = new QMenu("SnoreNotify");
|
||||
|
@ -76,8 +74,8 @@ QSystemTrayIcon *TrayIcon::trayIcon()
|
|||
void TrayIcon::slotTestNotification()
|
||||
{
|
||||
|
||||
if (!m_snore->aplications().contains(m_app.name())) {
|
||||
m_snore->registerApplication(m_app);
|
||||
if (!SnoreCore::instance().aplications().contains(m_app.name())) {
|
||||
SnoreCore::instance().registerApplication(m_app);
|
||||
}
|
||||
Notification noti(m_app, m_alert, "Hello World",
|
||||
"<i>This is Snore</i><br>"
|
||||
|
@ -88,7 +86,7 @@ void TrayIcon::slotTestNotification()
|
|||
"4<br>"
|
||||
"5<br>", Icon(":/root/snore.png"));
|
||||
noti.addAction(Action(1, "Test Action"));
|
||||
m_snore->broadcastNotification(noti);
|
||||
SnoreCore::instance().broadcastNotification(noti);
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
m_notifications[timer] = noti;
|
||||
|
@ -97,7 +95,7 @@ void TrayIcon::slotTestNotification()
|
|||
connect(timer, SIGNAL(timeout()), this, SLOT(sloutUpdateTestNotification()));
|
||||
timer->start();
|
||||
|
||||
// m_snore->deregisterApplication(app);
|
||||
// SnoreCore::instance().deregisterApplication(app);
|
||||
}
|
||||
|
||||
void TrayIcon::sloutUpdateTestNotification()
|
||||
|
@ -109,7 +107,7 @@ void TrayIcon::sloutUpdateTestNotification()
|
|||
"<u>This icon is quite a long line of text, isnt it I think it is what do you think? btw the icon should be in color</u><br>"
|
||||
"<a href=\"https://github.com/TheOneRing/Snorenotify\">Project Website</a>",
|
||||
Icon("http://winkde.org/~pvonreth/other/kde-logo.png"));
|
||||
m_snore->broadcastNotification(update);
|
||||
SnoreCore::instance().broadcastNotification(update);
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class TrayIcon: public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
TrayIcon();
|
||||
void initConextMenu(Snore::SnoreCore *snore);
|
||||
void initConextMenu();
|
||||
void hide();
|
||||
class QSystemTrayIcon *trayIcon();
|
||||
|
||||
|
@ -40,7 +40,6 @@ private:
|
|||
class QSystemTrayIcon *m_trayIcon;
|
||||
class QMenu *m_trayMenu;
|
||||
QActionGroup *m_backendActions;
|
||||
Snore::SnoreCore *m_snore;
|
||||
Snore::Application m_app;
|
||||
Snore::Alert m_alert;
|
||||
Snore::SettingsDialog *m_settings;
|
||||
|
|
|
@ -14,10 +14,10 @@ int main(int argc, char *argv[])
|
|||
app.setApplicationVersion(Snore::Version::version());
|
||||
app.setQuitOnLastWindowClosed(true);
|
||||
|
||||
Snore::SnoreCore snore;
|
||||
Snore::SnoreCore &snore = Snore::SnoreCore::instance();
|
||||
snore.loadPlugins(Snore::SnorePlugin::ALL);
|
||||
|
||||
Snore::SettingsDialog diag(&snore);
|
||||
Snore::SettingsDialog diag;
|
||||
// diag.setWindowIcon(QIcon(":/root/snore.png"));
|
||||
diag.setWindowTitle("SnoreSettings");
|
||||
diag.show();
|
||||
|
|
Loading…
Reference in New Issue