File indexing completed on 2024-05-05 04:57:29
0001 /* 0002 This file is part of Choqok, the KDE micro-blogging client 0003 0004 SPDX-FileCopyrightText: 2011-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #include "notifysettings.h" 0010 0011 #include <QDesktopWidget> 0012 #include <QMap> 0013 0014 #include <KConfigGroup> 0015 #include <KSharedConfig> 0016 0017 #include "accountmanager.h" 0018 0019 class NotifySettings::Private 0020 { 0021 public: 0022 QMap<QString, QStringList> accounts; 0023 KConfigGroup *accountsConf; 0024 KConfigGroup *conf; 0025 int interval; 0026 QPoint position; 0027 QColor foregroundColor; 0028 QColor backgroundColor; 0029 QFont font; 0030 }; 0031 0032 NotifySettings::NotifySettings(QObject *parent) 0033 : QObject(parent), d(new Private) 0034 { 0035 d->conf = new KConfigGroup(KSharedConfig::openConfig(), QLatin1String("BetterNotify Plugin")); 0036 d->accountsConf = new KConfigGroup(KSharedConfig::openConfig(), QLatin1String("BetterNotify Accounts Config")); 0037 load(); 0038 } 0039 0040 NotifySettings::~NotifySettings() 0041 { 0042 save(); 0043 delete d->accountsConf; 0044 } 0045 0046 QMap< QString, QStringList > NotifySettings::accounts() 0047 { 0048 return d->accounts; 0049 } 0050 0051 void NotifySettings::setAccounts(QMap< QString, QStringList > accounts) 0052 { 0053 d->accounts = accounts; 0054 } 0055 0056 void NotifySettings::load() 0057 { 0058 d->accounts.clear(); 0059 d->accountsConf->sync(); 0060 for (Choqok::Account *acc: Choqok::AccountManager::self()->accounts()) { 0061 d->accounts.insert(acc->alias(), d->accountsConf->readEntry(acc->alias(), QStringList())); 0062 } 0063 d->conf->sync(); 0064 d->interval = d->conf->readEntry("Interval", 7); 0065 QRect screenRect(QDesktopWidget().screenGeometry()); 0066 QPoint defaultPosition = QPoint(screenRect.center().x() - NOTIFICATION_WIDTH / 2, 30); 0067 d->position = d->conf->readEntry("NotifyPosition", defaultPosition); 0068 screenRect.adjust(0, 0, -1 * NOTIFICATION_WIDTH, -1 * NOTIFICATION_HEIGHT); 0069 if (!screenRect.contains(d->position)) { 0070 d->position = defaultPosition; 0071 } 0072 d->backgroundColor = d->conf->readEntry("NotifyBackground", QColor(0, 0, 0)); 0073 d->foregroundColor = d->conf->readEntry("NotifyForeground", QColor(255, 255, 255)); 0074 d->font = d->conf->readEntry("NotifyFont", QFont()); 0075 } 0076 0077 void NotifySettings::save() 0078 { 0079 for (Choqok::Account *acc: Choqok::AccountManager::self()->accounts()) { 0080 d->accountsConf->writeEntry(acc->alias(), d->accounts.value(acc->alias())); 0081 } 0082 d->conf->writeEntry("Interval", d->interval); 0083 d->conf->writeEntry("NotifyPosition", d->position); 0084 d->conf->writeEntry("NotifyBackground", d->backgroundColor); 0085 d->conf->writeEntry("NotifyForeground", d->foregroundColor); 0086 d->conf->writeEntry("NotifyFont", d->font); 0087 d->accountsConf->sync(); 0088 } 0089 0090 int NotifySettings::notifyInterval() const 0091 { 0092 return d->interval; 0093 } 0094 0095 void NotifySettings::setNotifyInterval(int interval) 0096 { 0097 d->interval = interval; 0098 } 0099 0100 QPoint NotifySettings::position() const 0101 { 0102 return d->position; 0103 } 0104 0105 void NotifySettings::setPosition(const QPoint &position) 0106 { 0107 d->position = position; 0108 } 0109 0110 QColor NotifySettings::backgroundColor() const 0111 { 0112 return d->backgroundColor; 0113 } 0114 0115 void NotifySettings::setBackgroundColor(const QColor &color) 0116 { 0117 d->backgroundColor = color; 0118 } 0119 0120 QFont NotifySettings::font() const 0121 { 0122 return d->font; 0123 } 0124 0125 void NotifySettings::setFont(const QFont &font) 0126 { 0127 d->font = font; 0128 } 0129 0130 QColor NotifySettings::foregroundColor() const 0131 { 0132 return d->foregroundColor; 0133 } 0134 0135 void NotifySettings::setForegroundColor(const QColor &color) 0136 { 0137 d->foregroundColor = color; 0138 }