From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- languages/sql/sqlactions.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 languages/sql/sqlactions.cpp (limited to 'languages/sql/sqlactions.cpp') diff --git a/languages/sql/sqlactions.cpp b/languages/sql/sqlactions.cpp new file mode 100644 index 00000000..8cfac095 --- /dev/null +++ b/languages/sql/sqlactions.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (C) 2003 by Harald Fernengel * + * harry@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "sqlactions.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kdevplugin.h" +#include "kdevlanguagesupport.h" +#include "sqlsupport_part.h" + +SqlListAction::SqlListAction(SQLSupportPart *part, const QString &text, + const KShortcut& cut, + const QObject *receiver, const char *slot, + KActionCollection *parent, const char *name) + : KWidgetAction( m_combo = new KComboBox(), text, cut, 0, 0, parent, name), m_part(part) +{ +#if (QT_VERSION >= 0x030100) + m_combo->setEditable( false ); + m_combo->setAutoCompletion( true ); +#endif + + m_combo->setMinimumWidth( 200 ); + m_combo->setMaximumWidth( 400 ); + + connect( m_combo, SIGNAL(activated(const QString&)), receiver, slot ); + connect( m_combo, SIGNAL(activated(int)), this, SLOT(activated(int)) ); + + setShortcutConfigurable( false ); + setAutoSized( true ); + + refresh(); +} + + +void SqlListAction::setCurrentConnectionName(const QString &name) +{ + int idx = m_part->connections().findIndex( name ); + if ( idx < 0 ) + m_combo->setCurrentItem( 0 ); + else + m_combo->setCurrentItem( idx + 1 ); +} + + +QString SqlListAction::currentConnectionName() const +{ + if ( m_combo->currentItem() <= 0 ) + return QString::null; + return m_part->connections()[ m_combo->currentItem() - 1 ]; +} + +void SqlListAction::activated(int idx) +{ + if (idx < 1 || (int)m_part->connections().count() <= idx) + return; + const QSqlDatabase *db = QSqlDatabase::database(m_part->connections()[idx], true); + m_combo->changeItem( db->isOpen() ? SmallIcon( "ok" ) : SmallIcon( "no" ), + m_combo->text(idx), idx ); +} + +void SqlListAction::refresh() +{ + const QStringList& dbc = m_part->connections(); + + m_combo->clear(); + m_combo->insertItem( i18n("") ); + + QString cName; + for ( QStringList::ConstIterator it = dbc.begin(); it != dbc.end(); ++it ) { + + QSqlDatabase* db = QSqlDatabase::database( (*it), false ); + if ( !db ) { + kdDebug( 9000 ) << "Could not find database connection " << (*it) << endl; + m_combo->insertItem( SmallIcon( "no" ), i18n("").arg( *it ) ); + continue; + } + cName = db->driverName(); + cName.append( "://" ).append( db->userName() ).append( "@" ).append( db->hostName() ); + cName.append( "/" ).append( db->databaseName() ); + + m_combo->insertItem( db->open() ? SmallIcon( "ok" ) : SmallIcon( "no" ), cName ); + } +} + + +#include "sqlactions.moc" -- cgit v1.2.3