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

kresources

  • kresources
configdialog.cpp
Go to the documentation of this file.
1/*
2 This file is part of libkresources.
3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
35#include "configdialog.h"
36#include <klocalizedstring.h>
37#include <klineedit.h>
38#include <kmessagebox.h>
39
40#include <QGroupBox>
41#include <QLabel>
42#include <QLayout>
43#include <QCheckBox>
44
45#include "factory.h"
46
47using namespace KRES;
48
49class ConfigDialog::Private
50{
51 public:
52 ConfigWidget *mConfigWidget;
53 Resource *mResource;
54 KLineEdit *mName;
55 QCheckBox *mReadOnly;
56};
57
58ConfigDialog::ConfigDialog( QWidget *parent, const QString &resourceFamily,
59 Resource *resource )
60 : KDialog( parent ), d( new Private )
61{
62 setModal( true );
63 setCaption( i18nc( "@title:window", "Resource Configuration" ) );
64 setButtons( Ok | Cancel );
65 setDefaultButton( Ok );
66 showButtonSeparator( false );
67
68 d->mResource = resource;
69 Factory *factory = Factory::self( resourceFamily );
70
71 QFrame *main = new QFrame( this );
72 setMainWidget( main );
73
74 QVBoxLayout *mainLayout = new QVBoxLayout( main );
75 mainLayout->setMargin( 0 );
76
77 QGroupBox *generalGroupBox = new QGroupBox( main );
78 QGridLayout *gbLayout = new QGridLayout;
79 generalGroupBox->setLayout( gbLayout );
80
81 generalGroupBox->setTitle( i18nc( "@title:group", "General Settings" ) );
82
83 gbLayout->addWidget( new QLabel( i18nc( "@label resource name", "Name:" ),
84 generalGroupBox ), 0, 0 );
85
86 d->mName = new KLineEdit();
87 gbLayout->addWidget( d->mName, 0, 1 );
88
89 d->mReadOnly =
90 new QCheckBox( i18nc( "@option:check if resource is read-only", "Read-only" ),
91 generalGroupBox );
92 gbLayout->addWidget( d->mReadOnly, 1, 0, 1, 2 );
93
94 d->mName->setText( d->mResource->resourceName() );
95 d->mReadOnly->setChecked( d->mResource->readOnly() );
96
97 mainLayout->addWidget( generalGroupBox );
98
99 QGroupBox *resourceGroupBox = new QGroupBox( main );
100 QGridLayout *resourceLayout = new QGridLayout;
101 resourceGroupBox->setLayout( resourceLayout );
102
103 resourceGroupBox->setTitle( i18nc( "@title:group", "%1 Resource Settings",
104 factory->typeName( resource->type() ) ) );
105 mainLayout->addWidget( resourceGroupBox );
106
107 mainLayout->addStretch();
108
109 d->mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox );
110 if ( d->mConfigWidget ) {
111 resourceLayout->addWidget( d->mConfigWidget );
112 d->mConfigWidget->setInEditMode( false );
113 d->mConfigWidget->loadSettings( d->mResource );
114 d->mConfigWidget->show();
115 connect( d->mConfigWidget, SIGNAL(setReadOnly(bool)),
116 SLOT(setReadOnly(bool)) );
117 }
118
119 connect( d->mName, SIGNAL(textChanged(QString)),
120 SLOT(slotNameChanged(QString)) );
121
122 slotNameChanged( d->mName->text() );
123 setMinimumSize( sizeHint() );
124}
125
126ConfigDialog::~ConfigDialog()
127{
128 delete d;
129}
130
131void ConfigDialog::setInEditMode( bool value )
132{
133 if ( d->mConfigWidget ) {
134 d->mConfigWidget->setInEditMode( value );
135 }
136}
137
138void ConfigDialog::slotNameChanged( const QString &text )
139{
140 enableButtonOk( !text.isEmpty() );
141}
142
143void ConfigDialog::setReadOnly( bool value )
144{
145 d->mReadOnly->setChecked( value );
146}
147
148void ConfigDialog::accept()
149{
150 if ( d->mName->text().isEmpty() ) {
151 KMessageBox::sorry( this, i18nc( "@info", "Please enter a resource name." ) );
152 return;
153 }
154
155 d->mResource->setResourceName( d->mName->text() );
156 d->mResource->setReadOnly( d->mReadOnly->isChecked() );
157
158 if ( d->mConfigWidget ) {
159 // First save generic information
160 // Also save setting of specific resource type
161 d->mConfigWidget->saveSettings( d->mResource );
162 }
163
164 KDialog::accept();
165}
166
KRES::ConfigWidget
An abstract base class for deriving resource configuration dialogs.
Definition: configwidget.h:48
KRES::ConfigWidget::setInEditMode
virtual void setInEditMode(bool value)
Sets the widget to 'edit' mode.
Definition: configwidget.cpp:45
KRES::Factory
A class for loading resource plugins.
Definition: factory.h:74
KRES::Factory::typeName
QString typeName(const QString &type) const
Returns the name for a special type.
Definition: factory.cpp:183
KRES::Factory::configWidget
ConfigWidget * configWidget(const QString &type, QWidget *parent=0)
Returns the config widget for the given resource type, or a null pointer if resource type doesn't exi...
Definition: factory.cpp:153
KRES::Factory::self
static Factory * self(const QString &resourceFamily)
Returns the global resource factory.
Definition: factory.cpp:68
KRES::Resource
This class provides a resource which is managed in a general way.
Definition: resource.h:76
KRES::Resource::type
QString type() const
Returns the type of this resource.
Definition: resource.cpp:169
configdialog.h
This file is part of the KDE resource framework and defines the ConfigDialog class.
factory.h
This file is part of the KDE resource framework and defines the Factory class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kresources

Skip menu "kresources"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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