korganizer Library API Documentation

configdialog.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 // Dialog for selecting and configuring the Holiday plugin 00021 00022 #include <qlayout.h> 00023 #include <qlabel.h> 00024 #include <qcombobox.h> 00025 00026 #include <klocale.h> 00027 #include <kmessagebox.h> 00028 #include <kapplication.h> 00029 #include <kglobal.h> 00030 #include <kconfig.h> 00031 #include <kstandarddirs.h> 00032 #include <ksimpleconfig.h> 00033 00034 #include "configdialog.h" 00035 #include "configdialog.moc" 00036 00037 ConfigDialog::ConfigDialog(QWidget *parent) 00038 : KDialogBase(Plain,i18n("Configure Holidays"),Ok|Cancel,Ok,parent) 00039 { 00040 QFrame *topFrame = plainPage(); 00041 QVBoxLayout *topLayout = new QVBoxLayout(topFrame,0,spacingHint()); 00042 00043 QLabel *label = new QLabel(i18n("Please select a holiday set:"),topFrame); 00044 topLayout->addWidget(label); 00045 00046 mHolidayCombo = new QComboBox(topFrame); 00047 topLayout->addWidget(mHolidayCombo); 00048 00049 load(); 00050 } 00051 00052 ConfigDialog::~ConfigDialog() 00053 { 00054 } 00055 00056 void ConfigDialog::load() 00057 { 00058 KConfig config( locateLocal( "config", "korganizerrc" )); 00059 config.setGroup("Calendar/Holiday Plugin"); 00060 QString currentHoliday = config.readEntry("Holidays"); 00061 QString currentHolidayName; 00062 00063 QStringList holidayList; 00064 QStringList countryList = KGlobal::dirs()->findAllResources("data", 00065 "korganizer/holiday_*", false, true); 00066 QStringList::ConstIterator it; 00067 for ( it = countryList.begin(); it != countryList.end(); ++it ) { 00068 QString country = (*it).mid((*it).findRev('_') + 1); 00069 QString countryFile = locate("locale","l10n/" + country + "/entry.desktop"); 00070 QString countryName; 00071 if (!countryFile.isEmpty()) { 00072 KSimpleConfig cfg(countryFile); 00073 cfg.setGroup("KCM Locale"); 00074 countryName = cfg.readEntry("Name"); 00075 } 00076 if (countryName.isEmpty()) countryName = country; 00077 00078 mCountryMap[countryName] = country; 00079 holidayList << countryName; 00080 00081 if (country == currentHoliday) currentHolidayName = countryName; 00082 } 00083 holidayList.sort(); 00084 00085 mHolidayCombo->insertStringList(holidayList); 00086 00087 for(int i=0;i<mHolidayCombo->count();++i) { 00088 if(mHolidayCombo->text(i) == currentHolidayName) { 00089 mHolidayCombo->setCurrentItem(i); 00090 break; 00091 } 00092 } 00093 } 00094 00095 void ConfigDialog::save() 00096 { 00097 QString currentHoliday = mCountryMap[mHolidayCombo->currentText()]; 00098 KConfig config( locateLocal( "config", "korganizerrc" )); 00099 00100 config.setGroup("Calendar/Holiday Plugin"); 00101 config.writeEntry("Holidays",currentHoliday); 00102 config.sync(); 00103 } 00104 00105 void ConfigDialog::slotOk() 00106 { 00107 save(); 00108 00109 accept(); 00110 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003