• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tderesources
 

tderesources

  • tderesources
selectdialog.cpp
1 /*
2  This file is part of libtderesources.
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 <kbuttonbox.h>
25 #include <tdelistbox.h>
26 #include <tdelocale.h>
27 #include <tdemessagebox.h>
28 
29 #include <tqgroupbox.h>
30 #include <tqlayout.h>
31 
32 #include "resource.h"
33 
34 #include "selectdialog.h"
35 
36 using namespace KRES;
37 
38 SelectDialog::SelectDialog( TQPtrList<Resource> list, TQWidget *parent,
39  const char *name )
40  : KDialog( parent, name, true )
41 {
42  setCaption( i18n( "Resource Selection" ) );
43  resize( 300, 200 );
44 
45  TQVBoxLayout *mainLayout = new TQVBoxLayout( this );
46  mainLayout->setMargin( marginHint() );
47 
48  TQGroupBox *groupBox = new TQGroupBox( 2, Qt::Horizontal, this );
49  groupBox->setTitle( i18n( "Resources" ) );
50 
51  mResourceId = new TDEListBox( groupBox );
52 
53  mainLayout->addWidget( groupBox );
54 
55  mainLayout->addSpacing( 10 );
56 
57  KButtonBox *buttonBox = new KButtonBox( this );
58 
59  buttonBox->addStretch();
60  buttonBox->addButton( KStdGuiItem::ok(), TQT_TQOBJECT(this), TQT_SLOT( accept() ) );
61  buttonBox->addButton( KStdGuiItem::cancel(), TQT_TQOBJECT(this), TQT_SLOT( reject() ) );
62  buttonBox->layout();
63 
64  mainLayout->addWidget( buttonBox );
65 
66  // setup listbox
67  uint counter = 0;
68  for ( uint i = 0; i < list.count(); ++i ) {
69  Resource *resource = list.at( i );
70  if ( resource && !resource->readOnly() ) {
71  mResourceMap.insert( counter, resource );
72  mResourceId->insertItem( resource->resourceName() );
73  counter++;
74  }
75  }
76 
77  mResourceId->setCurrentItem( 0 );
78  connect( mResourceId, TQT_SIGNAL(returnPressed(TQListBoxItem*)),
79  TQT_SLOT(accept()) );
80  connect( mResourceId, TQT_SIGNAL( executed( TQListBoxItem* ) ),
81  TQT_SLOT( accept() ) );
82 }
83 
84 Resource *SelectDialog::resource()
85 {
86  if ( mResourceId->currentItem() != -1 )
87  return mResourceMap[ mResourceId->currentItem() ];
88  else
89  return 0;
90 }
91 
92 Resource *SelectDialog::getResource( TQPtrList<Resource> list, TQWidget *parent )
93 {
94  if ( list.count() == 0 ) {
95  KMessageBox::error( parent, i18n( "There is no resource available!" ) );
96  return 0;
97  }
98 
99  if ( list.count() == 1 ) return list.first();
100 
101  // the following lines will return a writeable resource if only _one_ writeable
102  // resource exists
103  Resource *found = 0;
104  Resource *it = list.first();
105  while ( it ) {
106  if ( !it->readOnly() ) {
107  if ( found ) {
108  found = 0;
109  break;
110  } else
111  found = it;
112  }
113  it = list.next();
114  }
115 
116  if ( found )
117  return found;
118 
119  SelectDialog dlg( list, parent );
120  if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
121  else return 0;
122 }
KRES::Resource::resourceName
virtual TQString resourceName() const
Returns the name of resource.
Definition: resource.cpp:158
KRES::SelectDialog
Dialog for selecting a resource.
Definition: selectdialog.h:56
KRES::SelectDialog::resource
Resource * resource()
Returns selected resource.
Definition: selectdialog.cpp:84
KRES
Definition: configdialog.h:31
KRES::Resource
This class provides a resource which is managed in a general way.
Definition: resource.h:255
KRES::Resource::readOnly
virtual bool readOnly() const
Returns, if the resource is read-only.
Definition: resource.cpp:148
KRES::SelectDialog::SelectDialog
SelectDialog(TQPtrList< Resource > list, TQWidget *parent=0, const char *name=0)
Constructor.
Definition: selectdialog.cpp:38
KRES::SelectDialog::getResource
static Resource * getResource(TQPtrList< Resource > list, TQWidget *parent=0)
Opens a dialog showing the available resources and returns the resource the user has selected...
Definition: selectdialog.cpp:92

tderesources

Skip menu "tderesources"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tderesources

Skip menu "tderesources"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tderesources by doxygen 1.8.8
This website is maintained by Timothy Pearson.