File indexing completed on 2024-11-24 04:42:25
0001 /* 0002 * config.cpp - config functions 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2006-2019 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "config.h" 0010 0011 #include <KConfigGroup> 0012 #include <KSharedConfig> 0013 0014 #include <QApplication> 0015 #include <QScreen> 0016 0017 namespace Config 0018 { 0019 0020 /****************************************************************************** 0021 * Read the size for the specified window from the config file, for the 0022 * current screen resolution. 0023 * Reply = true if size set in the config file, in which case 'result' is set 0024 * = false if no size is set, in which case 'result' is unchanged. 0025 */ 0026 bool readWindowSize(const char* window, QSize& result, int* splitterWidth) 0027 { 0028 KConfigGroup config(KSharedConfig::openConfig(), QLatin1String(window)); 0029 const QSize desktopSize = QApplication::primaryScreen()->virtualSize(); 0030 const QSize s = QSize(config.readEntry(QStringLiteral("Width %1").arg(desktopSize.width()), (int)0), 0031 config.readEntry(QStringLiteral("Height %1").arg(desktopSize.height()), (int)0)); 0032 if (s.isEmpty()) 0033 return false; 0034 result = s; 0035 if (splitterWidth) 0036 *splitterWidth = config.readEntry(QStringLiteral("Splitter %1").arg(desktopSize.width()), -1); 0037 return true; 0038 } 0039 0040 /****************************************************************************** 0041 * Write the size for the specified window to the config file, for the 0042 * current screen resolution. 0043 */ 0044 void writeWindowSize(const char* window, const QSize& size, int splitterWidth) 0045 { 0046 KConfigGroup config(KSharedConfig::openConfig(), QLatin1String(window)); 0047 const QSize desktopSize = QApplication::primaryScreen()->virtualSize(); 0048 config.writeEntry(QStringLiteral("Width %1").arg(desktopSize.width()), size.width()); 0049 config.writeEntry(QStringLiteral("Height %1").arg(desktopSize.height()), size.height()); 0050 if (splitterWidth >= 0) 0051 config.writeEntry(QStringLiteral("Splitter %1").arg(desktopSize.width()), splitterWidth); 0052 config.sync(); 0053 } 0054 0055 } 0056 0057 // vim: et sw=4: