libkcal

resourcelocalconfig.cpp
1/*
2 This file is part of libkcal.
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 <typeinfo>
24
25#include <tqlabel.h>
26#include <tqlayout.h>
27
28#include <tdelocale.h>
29#include <tdemessagebox.h>
30#include <kdebug.h>
31#include <tdestandarddirs.h>
32
33#include "vcaldrag.h"
34#include "vcalformat.h"
35#include "icalformat.h"
36
37#include "resourcelocal.h"
38
39#include "resourcelocalconfig.h"
40
41using namespace KCal;
42
43ResourceLocalConfig::ResourceLocalConfig( TQWidget* parent, const char* name )
44 : KRES::ConfigWidget( parent, name )
45{
46 resize( 245, 115 );
47 TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 );
48
49 TQLabel *label = new TQLabel( i18n( "Location:" ), this );
50 mURL = new KURLRequester( this );
51 mainLayout->addWidget( label, 1, 0 );
52 mainLayout->addWidget( mURL, 1, 1 );
53
54 formatGroup = new TQButtonGroup( 1, TQt::Horizontal, i18n( "Calendar Format" ), this );
55
56 icalButton = new TQRadioButton( i18n("iCalendar"), formatGroup );
57 vcalButton = new TQRadioButton( i18n("vCalendar"), formatGroup );
58
59 mainLayout->addWidget( formatGroup, 2, 1 );
60}
61
62void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
63{
64 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
65 if ( res ) {
66 mURL->setURL( res->mURL.prettyURL() );
67 kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl;
68 if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) )
69 formatGroup->setButton( 0 );
70 else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) )
71 formatGroup->setButton( 1 );
72 else
73 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl;
74 } else
75 kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl;
76}
77
78void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
79{
80 TQString url = mURL->url();
81
82 if( url.isEmpty() ) {
83 TDEStandardDirs dirs;
84 TQString saveFolder = dirs.saveLocation( "data", "korganizer" );
85 TQFile file( saveFolder + "/std.ics" );
86
87 // find a non-existent name
88 for( int i = 0; file.exists(); ++i )
89 file.setName( saveFolder + "/std" + TQString::number(i) + ".ics" );
90
91 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() ) );
92
93 url = file.name();
94 }
95
96 ResourceLocal* res = static_cast<ResourceLocal*>( resource );
97 if (res) {
98 res->mURL = url;
99
100 delete res->mFormat;
101 if ( icalButton->isOn() ) {
102 res->mFormat = new ICalFormat();
103 } else {
104 res->mFormat = new VCalFormat();
105 }
106 } else
107 kdDebug(5800) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl;
108}
109
110#include "resourcelocalconfig.moc"
This class implements the iCalendar format.
Definition: icalformat.h:44
This class provides a calendar resource stored as a local file.
Definition: resourcelocal.h:46
This class implements the vCalendar format.
Definition: vcalformat.h:45
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38