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

kresources

  • kresources
selectdialog.cpp
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*/
23
24#include "selectdialog.h"
25
26#include <klocalizedstring.h>
27#include <kmessagebox.h>
28
29#include <QGroupBox>
30#include <QLayout>
31#include <QListWidget>
32
33#include "resource.h"
34
35using namespace KRES;
36
37class SelectDialog::SelectDialogPrivate
38{
39 public:
40 QListWidget *mResourceId;
41 QMap<int, Resource*> mResourceMap;
42};
43
44static bool resourceNameLessThan( Resource *a, Resource *b )
45{
46 return a->resourceName() < b->resourceName();
47}
48
49SelectDialog::SelectDialog( QList<Resource *> list, QWidget *parent )
50 : KDialog( parent ), d( new SelectDialogPrivate )
51{
52 setModal( true );
53 setCaption( i18n( "Resource Selection" ) );
54 resize( 300, 200 );
55 setButtons( Ok|Cancel );
56 setDefaultButton( Ok );
57
58 QWidget *widget = new QWidget( this );
59 setMainWidget( widget );
60
61 QVBoxLayout *mainLayout = new QVBoxLayout( widget );
62 mainLayout->setMargin( 0 );
63
64 QGroupBox *groupBox = new QGroupBox( widget );
65 QGridLayout *grid = new QGridLayout;
66 groupBox->setLayout( grid );
67 groupBox->setTitle( i18n( "Resources" ) );
68
69 d->mResourceId = new QListWidget( groupBox );
70 grid->addWidget( d->mResourceId, 0, 0 );
71
72 mainLayout->addWidget( groupBox );
73
74 // sort resources by name
75 qSort( list.begin(), list.end(), resourceNameLessThan );
76
77 // setup listbox
78 uint counter = 0;
79 for ( int i = 0; i < list.count(); ++i ) {
80 Resource *resource = list.at( i );
81 if ( resource && !resource->readOnly() ) {
82 d->mResourceMap.insert( counter, resource );
83 d->mResourceId->addItem( resource->resourceName() );
84 counter++;
85 }
86 }
87
88 d->mResourceId->setCurrentRow( 0 );
89 connect( d->mResourceId, SIGNAL(itemActivated(QListWidgetItem*)),
90 SLOT(accept()) );
91}
92
93SelectDialog::~SelectDialog()
94{
95 delete d;
96}
97
98Resource *SelectDialog::resource()
99{
100 if ( d->mResourceId->currentRow() != -1 ) {
101 return d->mResourceMap[ d->mResourceId->currentRow() ];
102 } else {
103 return 0;
104 }
105}
106
107Resource *SelectDialog::getResource( QList<Resource *> list, QWidget *parent )
108{
109 if ( list.count() == 0 ) {
110 KMessageBox::error( parent, i18n( "There is no resource available." ) );
111 return 0;
112 }
113
114 if ( list.count() == 1 ) {
115 return list.first();
116 }
117
118 // the following lines will return a writeable resource if only _one_
119 // writeable resource exists
120 Resource *found = 0;
121
122 for ( int i=0; i< list.size(); ++i ) {
123 if ( !list.at( i )->readOnly() ) {
124 if ( found ) {
125 found = 0;
126 break;
127 }
128 } else {
129 found = list.at( i );
130 }
131 }
132
133 if ( found ) {
134 return found;
135 }
136
137 SelectDialog dlg( list, parent );
138 if ( dlg.exec() == KDialog::Accepted ) {
139 return dlg.resource();
140 } else {
141 return 0;
142 }
143}
KRES::Manager
This class provides a manager for resources of a specified family.
Definition manager.h:83
KRES::Manager::end
Iterator end()
Return Iterator indicating end of resource list.
Definition manager.h:147
KRES::Manager::begin
Iterator begin()
Return Iterator on first resource.
Definition manager.h:137
KRES::Resource
This class provides a resource which is managed in a general way.
Definition resource.h:76
KRES::Resource::resourceName
virtual QString resourceName() const
Returns the name of resource.
Definition resource.cpp:189
KRES::Resource::readOnly
virtual bool readOnly() const
Returns, if the resource is read-only.
Definition resource.cpp:179
KRES::SelectDialog
Dialog for selecting a resource.
Definition selectdialog.h:57
KRES::SelectDialog::getResource
static Resource * getResource(QList< Resource * > list, QWidget *parent=0)
Opens a dialog showing the available resources and returns the resource the user has selected.
Definition selectdialog.cpp:107
KRES::SelectDialog::resource
Resource * resource()
Returns selected resource.
Definition selectdialog.cpp:98
KRES::SelectDialog::~SelectDialog
~SelectDialog()
Destructor.
Definition selectdialog.cpp:93
KRES::SelectDialog::SelectDialog
SelectDialog(QList< Resource * > list, QWidget *parent=0)
Constructor.
Definition selectdialog.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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