• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.5 API Reference
  • KDE Home
  • Contact Us
 

KCal Library

  • kcal
resourcelocalconfig.cpp
1 /*
2  This file is part of the kcal library.
3 
4  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "resourcelocalconfig.h"
24 #include "resourcelocal.h"
25 #include "resourcelocal_p.h"
26 #include "vcalformat.h"
27 #include "icalformat.h"
28 
29 #include <klocale.h>
30 #include <kmessagebox.h>
31 #include <kdebug.h>
32 #include <kstandarddirs.h>
33 
34 #include <QtGui/QLabel>
35 #include <QtGui/QGridLayout>
36 #include <QtGui/QGroupBox>
37 
38 #include <typeinfo>
39 
40 #include "resourcelocalconfig.moc"
41 
42 using namespace KCal;
43 
48 //@cond PRIVATE
49 class KCal::ResourceLocalConfig::Private
50 {
51  public:
52  Private()
53  {}
54  KUrlRequester *mURL;
55  QGroupBox *mFormatGroup;
56  QRadioButton *mIcalButton;
57  QRadioButton *mVcalButton;
58 };
59 //@endcond
60 
61 ResourceLocalConfig::ResourceLocalConfig( QWidget *parent )
62  : KRES::ConfigWidget( parent ), d( new KCal::ResourceLocalConfig::Private )
63 {
64  resize( 245, 115 );
65  QGridLayout *mainLayout = new QGridLayout( this );
66 
67  QLabel *label = new QLabel( i18n( "Location:" ), this );
68  d->mURL = new KUrlRequester( this );
69  d->mURL->setFilter( i18n( "*.ics *.vcs|Calendar Files" ) );
70  mainLayout->addWidget( label, 1, 0 );
71  mainLayout->addWidget( d->mURL, 1, 1 );
72 
73  d->mFormatGroup = new QGroupBox( i18n( "Calendar Format" ), this );
74 
75  d->mIcalButton = new QRadioButton( i18n( "iCalendar" ), d->mFormatGroup );
76  d->mVcalButton = new QRadioButton( i18n( "vCalendar" ), d->mFormatGroup );
77 
78  QVBoxLayout *vbox = new QVBoxLayout;
79  vbox->addWidget( d->mIcalButton );
80  vbox->addWidget( d->mVcalButton );
81  vbox->addStretch( 1 );
82  d->mFormatGroup->setLayout( vbox );
83 
84  mainLayout->addWidget( d->mFormatGroup, 2, 1 );
85 }
86 
87 ResourceLocalConfig::~ResourceLocalConfig()
88 {
89  delete d;
90 }
91 
92 void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
93 {
94  ResourceLocal* res = static_cast<ResourceLocal*>( resource );
95  if ( res ) {
96  d->mURL->setUrl( res->d->mURL.prettyUrl() );
97  kDebug() << "Format typeid().name():" << typeid( res->d->mFormat ).name();
98  if ( typeid( *(res->d->mFormat) ) == typeid( ICalFormat ) ) {
99  d->mIcalButton->setChecked(true);
100  } else if ( typeid( *(res->d->mFormat) ) == typeid( VCalFormat ) ) {
101  d->mVcalButton->setChecked(true);
102  } else {
103  kDebug() << "ERROR: Unknown format type";
104  }
105  } else {
106  kDebug() << "ERROR: no ResourceLocal, cast failed";
107  }
108 }
109 
110 void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
111 {
112  KUrl url = d->mURL->url();
113 
114  if( url.isEmpty() ) {
115  KStandardDirs dirs;
116  QString saveFolder = dirs.saveLocation( "data", "korganizer" );
117  QFile file( saveFolder + "/std.ics" );
118 
119  // find a non-existent name
120  for ( int i = 0; file.exists(); ++i ) {
121  file.setFileName( saveFolder + "/std" + QString::number(i) + ".ics" );
122  }
123 
124  KMessageBox::information(
125  this,
126  i18n( "You did not specify a URL for this resource. "
127  "Therefore, the resource will be saved in %1. "
128  "It is still possible to change this location "
129  "by editing the resource properties.", file.fileName() ) );
130 
131  url = KUrl::fromPath( file.fileName() );
132  }
133 
134  ResourceLocal* res = static_cast<ResourceLocal*>( resource );
135  if ( res ) {
136  res->d->mURL = url;
137 
138  delete res->d->mFormat;
139  if ( d->mIcalButton->isDown() ) {
140  res->d->mFormat = new ICalFormat();
141  } else {
142  res->d->mFormat = new VCalFormat();
143  }
144  } else {
145  kDebug() << "ERROR: no ResourceLocal, cast failed";
146  }
147 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jan 5 2013 19:47:23 by doxygen 1.8.1.2 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.9.5 API Reference

Skip menu "kdepimlibs-4.9.5 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