KDevelop API Documentation

languages/sql/sqlactions.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Harald Fernengel * 00003 * harry@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 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"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:06 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003