libkcal

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 <qlabel.h>
00026 #include <qlayout.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( QWidget* parent,  const char* name )
00044     : KRES::ConfigWidget( parent, name )
00045 {
00046   resize( 245, 115 ); 
00047   QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
00048 
00049   QLabel *label = new QLabel( i18n( "Location:" ), this );
00050   mURL = new KURLRequester( this );
00051   mainLayout->addWidget( label, 1, 0 );
00052   mainLayout->addWidget( mURL, 1, 1 );
00053 
00054   formatGroup = new QButtonGroup( 1, Horizontal, i18n( "Calendar Format" ), this );
00055 //  formatGroup->setExclusive( true );
00056 
00057 //  formatGroup->setFrameStyle(QFrame::NoFrame);
00058   icalButton = new QRadioButton( i18n("iCalendar"), formatGroup );
00059   vcalButton = new QRadioButton( i18n("vCalendar"), formatGroup );
00060 
00061   mainLayout->addWidget( formatGroup, 2, 1 );
00062 }
00063 
00064 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00065 {
00066   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00067   if ( res ) {
00068     mURL->setURL( res->mURL.prettyURL() );
00069     kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl;
00070     if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) )
00071       formatGroup->setButton( 0 );
00072     else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) )
00073       formatGroup->setButton( 1 );
00074     else 
00075       kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl;
00076   } else
00077     kdDebug(5700) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl;
00078 }
00079 
00080 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00081 {
00082   QString url = mURL->url();
00083 
00084   if( url.isEmpty() ) {
00085     KStandardDirs dirs;
00086     QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00087     QFile file( saveFolder + "/std.ics" );
00088     
00089     // find a non-existent name
00090     for( int i = 0; file.exists(); ++i )
00091       file.setName( saveFolder + "/std" + QString::number(i) + ".ics" );
00092     
00093     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() ) );
00094     
00095     url = file.name();
00096   }
00097 
00098   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00099   if (res) {
00100     res->mURL = url;
00101 
00102     delete res->mFormat;
00103     if ( icalButton->isOn() ) {
00104       res->mFormat = new ICalFormat();
00105     } else {
00106       res->mFormat = new VCalFormat();
00107     }
00108   } else
00109     kdDebug(5700) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl;
00110 }
00111 
00112 #include "resourcelocalconfig.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys