File indexing completed on 2024-04-28 04:50:47
0001 /* 0002 * configuration.cpp 0003 * 0004 * Copyright (C) 2011 Christoph Pfister <christophpfister@gmail.com> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation; either version 2 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License along 0017 * with this program; if not, write to the Free Software Foundation, Inc., 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0019 */ 0020 0021 #include "log.h" 0022 0023 #include <KConfig> 0024 #include <KConfigGroup> 0025 #include <KSharedConfig> 0026 0027 #include "configuration.h" 0028 0029 Configuration::Configuration() 0030 { 0031 startupDisplayMode = StartupNormalMode; 0032 int value = KSharedConfig::openConfig()->group("MainWindow").readEntry("StartupDisplayMode", 0033 static_cast<int>(startupDisplayMode)); 0034 0035 if ((value >= 0) && (value <= StartupLastValue)) { 0036 startupDisplayMode = static_cast<StartupDisplayMode>(value); 0037 } else { 0038 qCWarning(logConfig, "Unknown startup display mode %d", value); 0039 } 0040 0041 shortSkipDuration = 0042 KSharedConfig::openConfig()->group("MediaObject").readEntry("ShortSkipDuration", 15); 0043 longSkipDuration = 0044 KSharedConfig::openConfig()->group("MediaObject").readEntry("LongSkipDuration", 60); 0045 0046 libVlcArguments = 0047 KSharedConfig::openConfig()->group("libVlc").readEntry("Arguments", "--no-video-title-show"); 0048 } 0049 0050 Configuration::~Configuration() 0051 { 0052 } 0053 0054 void Configuration::detach() 0055 { 0056 if (globalInstance) { 0057 delete globalInstance; 0058 globalInstance = NULL; 0059 } 0060 } 0061 0062 Configuration *Configuration::instance() 0063 { 0064 if (globalInstance == NULL) { 0065 globalInstance = new Configuration(); 0066 } 0067 0068 return globalInstance; 0069 } 0070 0071 void Configuration::setStartupDisplayMode(int newStartupDisplayMode) 0072 { 0073 if ((newStartupDisplayMode >= 0) && (newStartupDisplayMode <= StartupLastValue)) { 0074 startupDisplayMode = static_cast<StartupDisplayMode>(newStartupDisplayMode); 0075 KSharedConfig::openConfig()->group("MainWindow").writeEntry("StartupDisplayMode", 0076 static_cast<int>(startupDisplayMode)); 0077 } else { 0078 qCWarning(logConfig, "Unknown startup display mode %d", newStartupDisplayMode); 0079 } 0080 } 0081 0082 void Configuration::setShortSkipDuration(int newShortSkipDuration) 0083 { 0084 shortSkipDuration = newShortSkipDuration; 0085 KSharedConfig::openConfig()->group("MediaObject").writeEntry("ShortSkipDuration", shortSkipDuration); 0086 emit shortSkipDurationChanged(shortSkipDuration); 0087 } 0088 0089 void Configuration::setLongSkipDuration(int newLongSkipDuration) 0090 { 0091 longSkipDuration = newLongSkipDuration; 0092 KSharedConfig::openConfig()->group("MediaObject").writeEntry("LongSkipDuration", longSkipDuration); 0093 emit longSkipDurationChanged(longSkipDuration); 0094 } 0095 0096 void Configuration::setLibVlcArguments(QString newArguments) 0097 { 0098 libVlcArguments = newArguments; 0099 KSharedConfig::openConfig()->group("libVlc").writeEntry("Arguments", libVlcArguments); 0100 // FIXME: allow changing it on runtime - maybe restarting kaffeine 0101 } 0102 0103 Configuration *Configuration::globalInstance = NULL; 0104 0105 #include "moc_configuration.cpp"