• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KCal Library

resourcelocalconfig.cpp

00001 /*
00002   This file is part of the kcal library.
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 "resourcelocalconfig.h"
00024 #include "resourcelocal.h"
00025 #include "resourcelocal_p.h"
00026 #include "vcalformat.h"
00027 #include "icalformat.h"
00028 
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031 #include <kdebug.h>
00032 #include <kstandarddirs.h>
00033 
00034 #include <QtGui/QLabel>
00035 #include <QtGui/QGridLayout>
00036 #include <QtGui/QGroupBox>
00037 
00038 #include <typeinfo>
00039 
00040 #include "resourcelocalconfig.moc"
00041 
00042 using namespace KCal;
00043 
00048 //@cond PRIVATE
00049 class KCal::ResourceLocalConfig::Private
00050 {
00051   public:
00052     Private()
00053     {}
00054     KUrlRequester *mURL;
00055     QGroupBox *mFormatGroup;
00056     QRadioButton *mIcalButton;
00057     QRadioButton *mVcalButton;
00058 };
00059 //@endcond
00060 
00061 ResourceLocalConfig::ResourceLocalConfig( QWidget *parent )
00062   : KRES::ConfigWidget( parent ), d( new KCal::ResourceLocalConfig::Private )
00063 {
00064   resize( 245, 115 );
00065   QGridLayout *mainLayout = new QGridLayout( this );
00066 
00067   QLabel *label = new QLabel( i18n( "Location:" ), this );
00068   d->mURL = new KUrlRequester( this );
00069   mainLayout->addWidget( label, 1, 0 );
00070   mainLayout->addWidget( d->mURL, 1, 1 );
00071 
00072   d->mFormatGroup = new QGroupBox( i18n( "Calendar Format" ), this );
00073 
00074   d->mIcalButton = new QRadioButton( i18n( "iCalendar" ), d->mFormatGroup );
00075   d->mVcalButton = new QRadioButton( i18n( "vCalendar" ), d->mFormatGroup );
00076 
00077   QVBoxLayout *vbox = new QVBoxLayout;
00078   vbox->addWidget( d->mIcalButton );
00079   vbox->addWidget( d->mVcalButton );
00080   vbox->addStretch( 1 );
00081   d->mFormatGroup->setLayout( vbox );
00082 
00083   mainLayout->addWidget( d->mFormatGroup, 2, 1 );
00084 }
00085 
00086 ResourceLocalConfig::~ResourceLocalConfig()
00087 {
00088   delete d;
00089 }
00090 
00091 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00092 {
00093   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00094   if ( res ) {
00095     d->mURL->setUrl( res->d->mURL.prettyUrl() );
00096     kDebug() << "Format typeid().name():" << typeid( res->d->mFormat ).name();
00097     if ( typeid( *(res->d->mFormat) ) == typeid( ICalFormat ) ) {
00098       d->mIcalButton->setChecked(true);
00099     } else if ( typeid( *(res->d->mFormat) ) == typeid( VCalFormat ) ) {
00100       d->mVcalButton->setChecked(true);
00101     } else {
00102       kDebug() << "ERROR: Unknown format type";
00103     }
00104   } else {
00105     kDebug() << "ERROR: no ResourceLocal, cast failed";
00106   }
00107 }
00108 
00109 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00110 {
00111   KUrl url = d->mURL->url();
00112 
00113   if( url.isEmpty() ) {
00114     KStandardDirs dirs;
00115     QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00116     QFile file( saveFolder + "/std.ics" );
00117 
00118     // find a non-existent name
00119     for ( int i = 0; file.exists(); ++i ) {
00120       file.setFileName( saveFolder + "/std" + QString::number(i) + ".ics" );
00121     }
00122 
00123     KMessageBox::information(
00124       this,
00125       i18n( "You did not specify a URL for this resource. "
00126             "Therefore, the resource will be saved in %1. "
00127             "It is still possible to change this location "
00128             "by editing the resource properties.", file.fileName() ) );
00129 
00130     url = KUrl::fromPath( file.fileName() );
00131   }
00132 
00133   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00134   if ( res ) {
00135     res->d->mURL = url;
00136 
00137     delete res->d->mFormat;
00138     if ( d->mIcalButton->isDown() ) {
00139       res->d->mFormat = new ICalFormat();
00140     } else {
00141       res->d->mFormat = new VCalFormat();
00142     }
00143   } else {
00144     kDebug() << "ERROR: no ResourceLocal, cast failed";
00145   }
00146 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal