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., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 // $Id: configdialog.cpp,v 1.5 2002/08/12 13:59:33 binner Exp $
00021 // Dialog for selecting and configuring the Holiday plugin
00022 
00023 #include <qlayout.h>
00024 #include <qlabel.h>
00025 #include <qcombobox.h>
00026 
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 #include <kapplication.h>
00030 #include <kglobal.h>
00031 #include <kconfig.h>
00032 #include <kstandarddirs.h>
00033 #include <ksimpleconfig.h>
00034 
00035 #include "configdialog.h"
00036 #include "configdialog.moc"
00037 
00038 ConfigDialog::ConfigDialog(QWidget *parent)
00039   : KDialogBase(Plain,i18n("Configure Holidays"),Ok,Ok,parent)
00040 {
00041   QFrame *topFrame = plainPage();
00042   QVBoxLayout *topLayout = new QVBoxLayout(topFrame,0,spacingHint());
00043 
00044   QLabel *label = new QLabel(i18n("Please select a holiday set:"),topFrame);
00045   topLayout->addWidget(label);
00046 
00047   mHolidayCombo = new QComboBox(topFrame);
00048   topLayout->addWidget(mHolidayCombo);
00049 
00050   load();
00051 }
00052 
00053 ConfigDialog::~ConfigDialog()
00054 {
00055 }
00056 
00057 void ConfigDialog::load()
00058 {
00059   kapp->config()->setGroup("Calendar/Holiday Plugin");
00060   QString currentHoliday = kapp->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 
00099   kapp->config()->setGroup("Calendar/Holiday Plugin");
00100   kapp->config()->writeEntry("Holidays",currentHoliday);
00101   kapp->config()->sync();
00102 }
00103 
00104 void ConfigDialog::slotOk()
00105 {
00106   save();
00107 
00108   accept();
00109 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001