00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "sqlactions.h"
00013
00014
#include <qpopupmenu.h>
00015
#include <qstringlist.h>
00016
#include <qsqldatabase.h>
00017
00018
#include <kdebug.h>
00019
#include <klocale.h>
00020
#include <ktoolbar.h>
00021
#include <kiconloader.h>
00022
#include <kcombobox.h>
00023
00024
#include "kdevplugin.h"
00025
#include "kdevlanguagesupport.h"
00026
#include "sqlsupport_part.h"
00027
00028 SqlListAction::SqlListAction(
SQLSupportPart *part,
const QString &text,
00029
const KShortcut& cut,
00030
const QObject *receiver,
const char *slot,
00031
KActionCollection *parent,
const char *name)
00032 :
KWidgetAction( m_combo = new
KComboBox(),
text, cut, 0, 0, parent, name), m_part(part)
00033 {
00034
#if (QT_VERSION >= 0x030100)
00035
m_combo->setEditable(
false );
00036
m_combo->
setAutoCompletion(
true );
00037
#endif
00038
00039
m_combo->setMinimumWidth( 200 );
00040
m_combo->setMaximumWidth( 400 );
00041
00042 connect(
m_combo, SIGNAL(
activated(
const QString&)), receiver, slot );
00043 connect(
m_combo, SIGNAL(
activated(
int)),
this, SLOT(
activated(
int)) );
00044
00045 setShortcutConfigurable(
false );
00046 setAutoSized(
true );
00047
00048
refresh();
00049 }
00050
00051
00052 void SqlListAction::setCurrentConnectionName(
const QString &name)
00053 {
00054
int idx =
m_part->
connections().findIndex( name );
00055
if ( idx < 0 )
00056
m_combo->
setCurrentItem( 0 );
00057
else
00058
m_combo->
setCurrentItem( idx + 1 );
00059 }
00060
00061
00062 QString SqlListAction::currentConnectionName()
const
00063
{
00064
if (
m_combo->currentItem() <= 0 )
00065
return QString::null;
00066
return m_part->
connections()[
m_combo->currentItem() - 1 ];
00067 }
00068
00069 void SqlListAction::activated(
int idx)
00070 {
00071
if (idx < 1 || (
int)
m_part->
connections().count() <= idx)
00072
return;
00073
const QSqlDatabase *db = QSqlDatabase::database(
m_part->
connections()[idx],
true);
00074
m_combo->changeItem( db->isOpen() ? SmallIcon(
"ok" ) : SmallIcon(
"no" ),
00075
m_combo->text(idx), idx );
00076 }
00077
00078 void SqlListAction::refresh()
00079 {
00080
const QStringList& dbc =
m_part->
connections();
00081
00082
m_combo->clear();
00083
m_combo->insertItem( i18n(
"<no database server>") );
00084
00085
QString cName;
00086
for ( QStringList::ConstIterator it = dbc.begin(); it != dbc.end(); ++it ) {
00087
00088
QSqlDatabase* db = QSqlDatabase::database( (*it),
false );
00089
if ( !db ) {
00090
kdDebug( 9000 ) <<
"Could not find database connection " << (*it) <<
endl;
00091
m_combo->insertItem( SmallIcon(
"no" ), i18n(
"<error - no connection %1>").arg( *it ) );
00092
continue;
00093 }
00094 cName = db->driverName();
00095 cName.append(
"://" ).append( db->userName() ).append(
"@" ).append( db->hostName() );
00096 cName.append(
"/" ).append( db->databaseName() );
00097
00098
m_combo->insertItem( db->open() ? SmallIcon(
"ok" ) : SmallIcon(
"no" ), cName );
00099 }
00100 }
00101
00102
00103
#include "sqlactions.moc"