• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • 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   d->mURL->setFilter( i18n( "*.ics *.vcs|Calendar Files" ) );
00070   mainLayout->addWidget( label, 1, 0 );
00071   mainLayout->addWidget( d->mURL, 1, 1 );
00072 
00073   d->mFormatGroup = new QGroupBox( i18n( "Calendar Format" ), this );
00074 
00075   d->mIcalButton = new QRadioButton( i18n( "iCalendar" ), d->mFormatGroup );
00076   d->mVcalButton = new QRadioButton( i18n( "vCalendar" ), d->mFormatGroup );
00077 
00078   QVBoxLayout *vbox = new QVBoxLayout;
00079   vbox->addWidget( d->mIcalButton );
00080   vbox->addWidget( d->mVcalButton );
00081   vbox->addStretch( 1 );
00082   d->mFormatGroup->setLayout( vbox );
00083 
00084   mainLayout->addWidget( d->mFormatGroup, 2, 1 );
00085 }
00086 
00087 ResourceLocalConfig::~ResourceLocalConfig()
00088 {
00089   delete d;
00090 }
00091 
00092 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
00093 {
00094   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00095   if ( res ) {
00096     d->mURL->setUrl( res->d->mURL.prettyUrl() );
00097     kDebug() << "Format typeid().name():" << typeid( res->d->mFormat ).name();
00098     if ( typeid( *(res->d->mFormat) ) == typeid( ICalFormat ) ) {
00099       d->mIcalButton->setChecked(true);
00100     } else if ( typeid( *(res->d->mFormat) ) == typeid( VCalFormat ) ) {
00101       d->mVcalButton->setChecked(true);
00102     } else {
00103       kDebug() << "ERROR: Unknown format type";
00104     }
00105   } else {
00106     kDebug() << "ERROR: no ResourceLocal, cast failed";
00107   }
00108 }
00109 
00110 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
00111 {
00112   KUrl url = d->mURL->url();
00113 
00114   if( url.isEmpty() ) {
00115     KStandardDirs dirs;
00116     QString saveFolder = dirs.saveLocation( "data", "korganizer" );
00117     QFile file( saveFolder + "/std.ics" );
00118 
00119     // find a non-existent name
00120     for ( int i = 0; file.exists(); ++i ) {
00121       file.setFileName( saveFolder + "/std" + QString::number(i) + ".ics" );
00122     }
00123 
00124     KMessageBox::information(
00125       this,
00126       i18n( "You did not specify a URL for this resource. "
00127             "Therefore, the resource will be saved in %1. "
00128             "It is still possible to change this location "
00129             "by editing the resource properties.", file.fileName() ) );
00130 
00131     url = KUrl::fromPath( file.fileName() );
00132   }
00133 
00134   ResourceLocal* res = static_cast<ResourceLocal*>( resource );
00135   if ( res ) {
00136     res->d->mURL = url;
00137 
00138     delete res->d->mFormat;
00139     if ( d->mIcalButton->isDown() ) {
00140       res->d->mFormat = new ICalFormat();
00141     } else {
00142       res->d->mFormat = new VCalFormat();
00143     }
00144   } else {
00145     kDebug() << "ERROR: no ResourceLocal, cast failed";
00146   }
00147 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:43 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

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

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal