1 | /* |
2 | This file is part of the kcal library. |
3 | |
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "resourcelocaldirconfig.h" |
23 | #include "resourcelocaldir.h" |
24 | #include "resourcelocaldir_p.h" |
25 | |
26 | #include <klocalizedstring.h> |
27 | #include <kdebug.h> |
28 | #include <kstandarddirs.h> |
29 | #include <kurlrequester.h> |
30 | #include <KMessageBox> |
31 | |
32 | #include <QLabel> |
33 | #include <QLayout> |
34 | #include <QGridLayout> |
35 | |
36 | #include <typeinfo> |
37 | |
38 | |
39 | using namespace KCal; |
40 | |
41 | /** |
42 | Private class that helps to provide binary compatibility between releases. |
43 | @internal |
44 | */ |
45 | //@cond PRIVATE |
46 | class KCal::ResourceLocalDirConfig::Private |
47 | { |
48 | public: |
49 | Private() |
50 | {} |
51 | KUrlRequester *mURL; |
52 | }; |
53 | //@endcond |
54 | |
55 | ResourceLocalDirConfig::ResourceLocalDirConfig( QWidget *parent ) |
56 | : KRES::ConfigWidget( parent ), d( new KCal::ResourceLocalDirConfig::Private ) |
57 | { |
58 | resize( 245, 115 ); |
59 | QGridLayout *mainLayout = new QGridLayout( this ); |
60 | |
61 | QLabel *label = new QLabel( i18n( "Location:" ), this ); |
62 | d->mURL = new KUrlRequester( this ); |
63 | d->mURL->setMode( KFile::Directory | KFile::LocalOnly ); |
64 | mainLayout->addWidget( label, 1, 0 ); |
65 | mainLayout->addWidget( d->mURL, 1, 1 ); |
66 | } |
67 | |
68 | ResourceLocalDirConfig::~ResourceLocalDirConfig() |
69 | { |
70 | delete d; |
71 | } |
72 | |
73 | void ResourceLocalDirConfig::loadSettings( KRES::Resource *resource ) |
74 | { |
75 | ResourceLocalDir *res = static_cast<ResourceLocalDir*>( resource ); |
76 | if ( res ) { |
77 | d->mURL->setUrl( res->d->mURL.prettyUrl() ); |
78 | } else { |
79 | kDebug() << "ERROR: no ResourceLocalDir, cast failed" ; |
80 | } |
81 | } |
82 | |
83 | void ResourceLocalDirConfig::saveSettings( KRES::Resource *resource ) |
84 | { |
85 | ResourceLocalDir *res = static_cast<ResourceLocalDir*>( resource ); |
86 | if (res) { |
87 | res->d->mURL = d->mURL->url(); |
88 | if ( d->mURL->url().isEmpty() && !resource->readOnly() ) { |
89 | KMessageBox::information( |
90 | this, |
91 | i18nc( "@info" , "No location specified. The calendar will be invalid." ), |
92 | QString(), |
93 | "ResourceLocalDirUrl" ); |
94 | resource->setReadOnly( true ); |
95 | } |
96 | } else { |
97 | kDebug() << "ERROR: no ResourceLocalDir, cast failed" ; |
98 | } |
99 | } |
100 | |