kitchensync Library API Documentation

localkonnectorconfig.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include "localkonnectorconfig.h" 00023 00024 #include "localkonnector.h" 00025 00026 #include <libkcal/resourcelocal.h> 00027 00028 #include <kconfig.h> 00029 #include <klocale.h> 00030 #include <kabc/resourcefile.h> 00031 #include <kmessagebox.h> 00032 #include <kinputdialog.h> 00033 #include <klineedit.h> 00034 00035 #include <qlabel.h> 00036 #include <qlayout.h> 00037 #include <qpushbutton.h> 00038 00039 using namespace KSync; 00040 00041 LocalKonnectorConfig::LocalKonnectorConfig( QWidget *parent ) 00042 : KRES::ConfigWidget( parent, 0 ) 00043 { 00044 QBoxLayout *topLayout = new QVBoxLayout( this ); 00045 00046 topLayout->addWidget( new QLabel( i18n("Calendar file:"), this ) ); 00047 00048 mCalendarFile = new KURLRequester( this ); 00049 mCalendarFile->setMode( KFile::File | KFile::LocalOnly ); 00050 topLayout->addWidget( mCalendarFile ); 00051 00052 QPushButton *button = 00053 new QPushButton( i18n("Select From Existing Resources..."), this ); 00054 connect( button, SIGNAL( clicked() ), SLOT( selectCalendarResource() ) ); 00055 topLayout->addWidget( button ); 00056 00057 topLayout->addSpacing( 4 ); 00058 00059 topLayout->addWidget( new QLabel( i18n("Address book file:"), this ) ); 00060 00061 mAddressBookFile = new KURLRequester( this ); 00062 mAddressBookFile->setMode( KFile::File | KFile::LocalOnly ); 00063 topLayout->addWidget( mAddressBookFile ); 00064 00065 button = new QPushButton( i18n("Select From Existing Resources..."), this ); 00066 connect( button, SIGNAL( clicked() ), SLOT( selectAddressBookResource() ) ); 00067 topLayout->addWidget( button ); 00068 } 00069 00070 LocalKonnectorConfig::~LocalKonnectorConfig() 00071 { 00072 } 00073 00074 void LocalKonnectorConfig::loadSettings( KRES::Resource *r ) 00075 { 00076 LocalKonnector *konnector = dynamic_cast<LocalKonnector *>( r ); 00077 if ( konnector ) { 00078 mCalendarFile->setURL( konnector->calendarFile() ); 00079 mAddressBookFile->setURL( konnector->addressBookFile() ); 00080 } 00081 } 00082 00083 void LocalKonnectorConfig::saveSettings( KRES::Resource *r ) 00084 { 00085 LocalKonnector *konnector = dynamic_cast<LocalKonnector *>( r ); 00086 if ( konnector ) { 00087 konnector->setCalendarFile( mCalendarFile->url() ); 00088 konnector->setAddressBookFile( mAddressBookFile->url() ); 00089 } 00090 } 00091 00092 void LocalKonnectorConfig::selectAddressBookResource() 00093 { 00094 QStringList files; 00095 00096 KRES::Manager<KABC::Resource> manager( "contact" ); 00097 manager.readConfig(); 00098 00099 KRES::Manager<KABC::Resource>::Iterator it; 00100 for( it = manager.begin(); it != manager.end(); ++it ) { 00101 if ( (*it)->inherits( "KABC::ResourceFile" ) ) { 00102 KABC::ResourceFile *r = static_cast<KABC::ResourceFile *>( *it ); 00103 files.append( r->fileName() ); 00104 } 00105 } 00106 00107 if ( files.isEmpty() ) { 00108 KMessageBox::sorry( this, i18n("No file resources found.") ); 00109 } else { 00110 QString file = KInputDialog::getItem( i18n("Select File"), 00111 i18n("Please select an addressbook file:"), files, 0, false, 0, this ); 00112 if ( !file.isEmpty() ) { 00113 mAddressBookFile->lineEdit()->setText( file ); 00114 } 00115 } 00116 } 00117 00118 void LocalKonnectorConfig::selectCalendarResource() 00119 { 00120 QStringList files; 00121 00122 KCal::CalendarResourceManager manager( "calendar" ); 00123 manager.readConfig(); 00124 00125 KCal::CalendarResourceManager::Iterator it; 00126 for( it = manager.begin(); it != manager.end(); ++it ) { 00127 if ( (*it)->inherits( "KCal::ResourceLocal" ) ) { 00128 KCal::ResourceLocal *r = static_cast<KCal::ResourceLocal *>( *it ); 00129 files.append( r->fileName() ); 00130 } 00131 } 00132 00133 if ( files.isEmpty() ) { 00134 KMessageBox::sorry( this, i18n("No file resources found.") ); 00135 } else { 00136 QString file = KInputDialog::getItem( i18n("Select File"), 00137 i18n("Please select a calendar file:"), files, 0, false, 0, this ); 00138 if ( !file.isEmpty() ) { 00139 mCalendarFile->lineEdit()->setText( file ); 00140 } 00141 } 00142 } 00143 00144 #include "localkonnectorconfig.moc"
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:48 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003