summaryrefslogtreecommitdiffstats
path: root/tderesources/remote/resourceremoteconfig.cpp
blob: 381134b01da1fcc6c7380ce9d714fc4ca76e6317 (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
/*
    This file is part of libkcal.

    Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.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 <tdelocale.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <kdialog.h>

#include <libkcal/resourcecachedconfig.h>

#include "resourceremote.h"

#include "resourceremoteconfig.h"

using namespace KCal;

ResourceRemoteConfig::ResourceRemoteConfig( TQWidget* parent,  const char* name )
    : KRES::ConfigWidget( parent, name )
{
  resize( 245, 115 ); 
  TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 );
  mainLayout->setSpacing( KDialog::spacingHint() );

  TQLabel *label = new TQLabel( i18n( "Download from:" ), this );

  mDownloadUrl = new KURLRequester( this );
  mDownloadUrl->setMode( KFile::File );
  mainLayout->addWidget( label, 1, 0 );
  mainLayout->addWidget( mDownloadUrl, 1, 1 );

  label = new TQLabel( i18n( "Upload to:" ), this );
  mUploadUrl = new KURLRequester( this );
  mUploadUrl->setMode( KFile::File );
  mainLayout->addWidget( label, 2, 0 );
  mainLayout->addWidget( mUploadUrl, 2, 1 );

  mReloadConfig = new ResourceCachedReloadConfig( this );
  mainLayout->addMultiCellWidget( mReloadConfig, 3, 3, 0, 1 );

  mSaveConfig = new ResourceCachedSaveConfig( this );
  mainLayout->addMultiCellWidget( mSaveConfig, 4, 4, 0, 1 );
}

void ResourceRemoteConfig::loadSettings( KRES::Resource *resource )
{
  ResourceRemote *res = static_cast<ResourceRemote *>( resource );
  if ( res ) {
    mDownloadUrl->setURL( res->downloadUrl().url() );
    mUploadUrl->setURL( res->uploadUrl().url() );
    mReloadConfig->loadSettings( res );
    mSaveConfig->loadSettings( res );
  } else {
    kdError(5700) << "ResourceRemoteConfig::loadSettings(): no ResourceRemote, cast failed" << endl;
  }
}

void ResourceRemoteConfig::saveSettings( KRES::Resource *resource )
{
  ResourceRemote* res = static_cast<ResourceRemote*>( resource );
  if ( res ) {
    res->setDownloadUrl( KURL( mDownloadUrl->url() ) );
    res->setUploadUrl( KURL( mUploadUrl->url() ) );
    mReloadConfig->saveSettings( res );
    mSaveConfig->saveSettings( res );


    if ( mUploadUrl->url().isEmpty() && !resource->readOnly() ) {
      KMessageBox::information( this, i18n( "You have specified no upload URL, "
			    "the calendar will be read-only." ), "RemoteResourseNoUploadURL" );
      resource->setReadOnly( true );
    }
  } else {
    kdError(5700) << "ResourceRemoteConfig::saveSettings(): no ResourceRemote, cast failed" << endl;
  }
}

#include "resourceremoteconfig.moc"