summaryrefslogtreecommitdiffabout
path: root/microkde/kresources/selectdialog.cpp
Unidiff
Diffstat (limited to 'microkde/kresources/selectdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/selectdialog.cpp154
1 files changed, 154 insertions, 0 deletions
diff --git a/microkde/kresources/selectdialog.cpp b/microkde/kresources/selectdialog.cpp
new file mode 100644
index 0000000..fba8648
--- a/dev/null
+++ b/microkde/kresources/selectdialog.cpp
@@ -0,0 +1,154 @@
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
22*/
23
24/*US
25#include <kbuttonbox.h>
26#include <klistbox.h>
27#include <klocale.h>
28#include <kmessagebox.h>
29
30*/
31#include <klocale.h>
32#include <kmessagebox.h>
33
34//US
35#include <kglobal.h>
36
37#include <qlistbox.h>
38#include <qlayout.h>
39#include <qgroupbox.h>
40
41#include "resource.h"
42
43#include "selectdialog.h"
44
45using namespace KRES;
46
47//US I am using KBaseDialog instead of KDialog
48//US : KDialog( parent, name, true )
49SelectDialog::SelectDialog( QPtrList<Resource> list, QWidget *parent,
50 const char *name )
51 : KDialogBase( parent, name, true, i18n( "Resource Selection" ), Help | Ok | Cancel,
52 Ok, true)
53
54{
55//US setCaption( i18n( "Resource Selection" ) );
56//US resize( 300, 200 );
57 resize( KMIN(KGlobal::getDesktopWidth(), 300), KMIN(KGlobal::getDesktopHeight(), 200) );
58
59//US
60 QFrame *main = plainPage();
61/*US
62 QVBoxLayout *layout = new QVBoxLayout( main );
63 mConfigPage = new KRES::ConfigPage( main );
64 layout->addWidget( mConfigPage );
65*/
66
67//US QVBoxLayout *mainLayout = new QVBoxLayout( this );
68 QVBoxLayout *mainLayout = new QVBoxLayout( main );
69 mainLayout->setMargin( marginHint() );
70
71//US QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, this );
72 QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, main );
73 groupBox->setTitle( i18n( "Resources" ) );
74
75//US mResourceId = new KListBox( groupBox );
76 mResourceId = new QListBox( groupBox );
77
78 mainLayout->addWidget( groupBox );
79
80 mainLayout->addSpacing( 40 );
81
82/*US
83 KButtonBox *buttonBox = new KButtonBox( this );
84
85 buttonBox->addStretch();
86 buttonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) );
87 buttonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
88 buttonBox->layout();
89
90 mainLayout->addWidget( buttonBox );
91*/
92 // setup listbox
93 uint counter = 0;
94 for ( uint i = 0; i < list.count(); ++i ) {
95 Resource *resource = list.at( i );
96 if ( resource && !resource->readOnly() ) {
97 mResourceMap.insert( counter, resource );
98 mResourceId->insertItem( resource->resourceName() );
99 counter++;
100 }
101 }
102
103 mResourceId->setCurrentItem( 0 );
104 connect( mResourceId, SIGNAL(returnPressed(QListBoxItem*)),
105 SLOT(accept()) );
106}
107
108Resource *SelectDialog::resource()
109{
110 if ( mResourceId->currentItem() != -1 )
111 return mResourceMap[ mResourceId->currentItem() ];
112 else
113 return 0;
114}
115
116Resource *SelectDialog::getResource( QPtrList<Resource> list, QWidget *parent )
117{
118 if ( list.count() == 0 ) {
119 KMessageBox::error( parent, i18n( "There is no resource available!" ) );
120 return 0;
121 }
122
123 if ( list.count() == 1 ) return list.first();
124
125 // the following lines will return a writeable resource if only _one_ writeable
126 // resource exists
127 Resource *found = 0;
128 Resource *it = list.first();
129 while ( it ) {
130 if ( !it->readOnly() ) {
131 if ( found ) {
132 found = 0;
133 break;
134 } else
135 found = it;
136 }
137 it = list.next();
138 }
139
140 if ( found )
141 return found;
142
143 SelectDialog dlg( list, parent);
144//US if ( dlg.exec() == KDialog::Accepted )
145 if ( dlg.exec() )
146 return dlg.resource();
147 else
148 return 0;
149}
150
151/*US
152#include "selectdialog.moc"
153*/
154