summaryrefslogtreecommitdiffstats
path: root/libkcal/resourcelocalconfig.cpp
blob: 50c909bf0f04391ddbff27db2c9555d702f1582d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
    This file is part of libkcal.

    Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
    Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <typeinfo>

#include <tqlabel.h>
#include <tqlayout.h>

#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <kstandarddirs.h>

#include "vcaldrag.h"
#include "vcalformat.h"
#include "icalformat.h"

#include "resourcelocal.h"

#include "resourcelocalconfig.h"

using namespace KCal;

ResourceLocalConfig::ResourceLocalConfig( TQWidget* parent,  const char* name )
    : KRES::ConfigWidget( parent, name )
{
  resize( 245, 115 ); 
  TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 );

  TQLabel *label = new TQLabel( i18n( "Location:" ), this );
  mURL = new KURLRequester( this );
  mainLayout->addWidget( label, 1, 0 );
  mainLayout->addWidget( mURL, 1, 1 );

  formatGroup = new TQButtonGroup( 1, Qt::Horizontal, i18n( "Calendar Format" ), this );

  icalButton = new TQRadioButton( i18n("iCalendar"), formatGroup );
  vcalButton = new TQRadioButton( i18n("vCalendar"), formatGroup );

  mainLayout->addWidget( formatGroup, 2, 1 );
}

void ResourceLocalConfig::loadSettings( KRES::Resource *resource )
{
  ResourceLocal* res = static_cast<ResourceLocal*>( resource );
  if ( res ) {
    mURL->setURL( res->mURL.prettyURL() );
    kdDebug(5800) << "Format typeid().name(): " << typeid( res->mFormat ).name() << endl;
    if ( typeid( *(res->mFormat) ) == typeid( ICalFormat ) )
      formatGroup->setButton( 0 );
    else if ( typeid( *(res->mFormat) ) == typeid( VCalFormat ) )
      formatGroup->setButton( 1 );
    else 
      kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): Unknown format type" << endl;
  } else
    kdDebug(5800) << "ERROR: ResourceLocalConfig::loadSettings(): no ResourceLocal, cast failed" << endl;
}

void ResourceLocalConfig::saveSettings( KRES::Resource *resource )
{
  TQString url = mURL->url();

  if( url.isEmpty() ) {
    KStandardDirs dirs;
    TQString saveFolder = dirs.saveLocation( "data", "korganizer" );
    TQFile file( saveFolder + "/std.ics" );
    
    // find a non-existent name
    for( int i = 0; file.exists(); ++i )
      file.setName( saveFolder + "/std" + TQString::number(i) + ".ics" );
    
    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() ) );
    
    url = file.name();
  }

  ResourceLocal* res = static_cast<ResourceLocal*>( resource );
  if (res) {
    res->mURL = url;

    delete res->mFormat;
    if ( icalButton->isOn() ) {
      res->mFormat = new ICalFormat();
    } else {
      res->mFormat = new VCalFormat();
    }
  } else
    kdDebug(5800) << "ERROR: ResourceLocalConfig::saveSettings(): no ResourceLocal, cast failed" << endl;
}

#include "resourcelocalconfig.moc"