kexi

kexidbdrivercombobox.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidbdrivercombobox.h"
21
22#include <tqlistbox.h>
23
24#include <kiconloader.h>
25
26KexiDBDriverComboBox::KexiDBDriverComboBox(TQWidget* parent, const KexiDB::Driver::InfoMap& driversInfo,
27 Options options)
28 : KComboBox(parent, "KexiDBDriverComboBox")
29{
30 //retrieve list of drivers and sort it: file-based first, then server-based
31 TQStringList captionsForFileBasedDrivers, captionsForServerBasedDrivers;
32 TQMap<TQString,TQString> fileBasedDriversDict, serverBasedDriversDict; //a map from caption to name
33 foreach(KexiDB::Driver::InfoMap::ConstIterator, it, driversInfo) {
34 if (it.data().fileBased) {
35 captionsForFileBasedDrivers += it.data().caption;
36 fileBasedDriversDict[it.data().caption] = it.data().name.lower();
37 }
38 else {
39 captionsForServerBasedDrivers += it.data().caption;
40 serverBasedDriversDict[it.data().caption] = it.data().name.lower();
41 }
42 }
43 captionsForFileBasedDrivers.sort();
44 captionsForServerBasedDrivers.sort();
45 //insert file-based
46 if (options & ShowFileDrivers) {
47 foreach(TQStringList::ConstIterator, it, captionsForFileBasedDrivers) {
48 const KexiDB::Driver::Info& info = driversInfo[ fileBasedDriversDict[ *it ] ];
50 insertItem( SmallIcon("gear"), info.caption );
51 m_driversMap.insert(info.caption, info.name.lower());
52 }
53 }
54 //insert server-based
55 if (options & ShowServerDrivers) {
56 foreach(TQStringList::ConstIterator, it, captionsForServerBasedDrivers) {
57 const KexiDB::Driver::Info& info = driversInfo[ serverBasedDriversDict[ *it ] ];
59 insertItem( SmallIcon("gear"), info.caption );
60 m_driversMap.insert(info.caption, info.name.lower());
61 }
62 }
63// if (listBox())
64// listBox()->sort();
65
66 // Build the names list after sorting
67 for (int i=0; i<count(); i++)
68 m_driverNames += m_driversMap[ text(i) ];
69}
70
71KexiDBDriverComboBox::~KexiDBDriverComboBox()
72{
73}
74
76{
77 TQMapConstIterator<TQString,TQString> it( m_driversMap.find( text( currentItem() ) ) );
78 if (it==m_driversMap.constEnd())
79 return TQString();
80 return it.data();
81}
82
83void KexiDBDriverComboBox::setDriverName(const TQString& driverName)
84{
85 int index = m_driverNames.findIndex( driverName.lower() );
86 if (index==-1) {
87 return;
88 }
89 setCurrentItem(index);
90}
91
92#include "kexidbdrivercombobox.moc"
KexiDBDriverComboBox(TQWidget *parent, const KexiDB::Driver::InfoMap &driversInfo, Options options=ShowAll)
TQString selectedDriverName() const
void setDriverName(const TQString &driverName)