resourcelocalconfig.cpp
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 00005 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include <typeinfo> 00024 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 00028 #include <klocale.h> 00029 #include <kmessagebox.h> 00030 #include <kdebug.h> 00031 #include <kstandarddirs.h> 00032 00033 #include "vcaldrag.h" 00034 #include "vcalformat.h" 00035 #include "icalformat.h" 00036 00037 #include "resourcelocal.h" 00038 00039 #include "resourcelocalconfig.h" 00040 00041 using namespace KCal; 00042 00043 ResourceLocalConfig::ResourceLocalConfig( TQWidget* parent, const char* name ) 00044 : KRES::ConfigWidget( parent, name ) 00045 { 00046 resize( 245, 115 ); 00047 TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 ); 00048 00049 TQLabel *label = new TQLabel( i18n( "Location:" ), this ); 00050 mURL = new KURLRequester( this ); 00051 mainLayout->addWidget( label, 1, 0 ); 00052 mainLayout->addWidget( mURL, 1, 1 ); 00053 00054 formatGroup = new TQButtonGroup( 1, Qt::Horizontal, i18n( "Calendar Format" ), this ); 00055 00056 icalButton = new TQRadioButton( i18n("iCalendar"), formatGroup ); 00057 vcalButton = new TQRadioButton( i18n("vCalendar"), formatGroup ); 00058 00059 mainLayout->addWidget( formatGroup, 2, 1 ); 00060 } 00061 00062 void ResourceLocalConfig::loadSettings( KRES::Resource *resource ) 00063 { 00064 ResourceLocal* res = static_cast<ResourceLocal*>( resource ); 00065 if ( res ) { 00066 mURL->setURL( res->mURL.prettyURL() ); 00067 kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl; 00068 if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) ) 00069 formatGroup->setButton( 0 ); 00070 else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) ) 00071 formatGroup->setButton( 1 ); 00072 else 00073 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl; 00074 } else 00075 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl; 00076 } 00077 00078 void ResourceLocalConfig::saveSettings( KRES::Resource *resource ) 00079 { 00080 TQString url = mURL->url(); 00081 00082 if( url.isEmpty() ) { 00083 KStandardDirs dirs; 00084 TQString saveFolder = dirs.saveLocation( "data", "korganizer" ); 00085 TQFile file( saveFolder + "/std.ics" ); 00086 00087 // find a non-existent name 00088 for( int i = 0; file.exists(); ++i ) 00089 file.setName( saveFolder + "/std" + TQString::number(i) + ".ics" ); 00090 00091 KMessageBox::information( this, i18n( "You did not specify a URL for this resource. Therefore, the resource will be saved in %1. It is still possible to change this location by editing the resource properties." ).arg( file.name() ) ); 00092 00093 url = file.name(); 00094 } 00095 00096 ResourceLocal* res = static_cast<ResourceLocal*>( resource ); 00097 if (res) { 00098 res->mURL = url; 00099 00100 delete res->mFormat; 00101 if ( icalButton->isOn() ) { 00102 res->mFormat = new ICalFormat(); 00103 } else { 00104 res->mFormat = new VCalFormat(); 00105 } 00106 } else 00107 kdDebug(5800) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl; 00108 } 00109 00110 #include "resourcelocalconfig.moc"