languageselectwidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qstring.h>
00013 #include <qvariant.h>
00014 #include <qheader.h>
00015 #include <qlabel.h>
00016 #include <qlayout.h>
00017 #include <qlistview.h>
00018 #include <qgroupbox.h>
00019 #include <qhbox.h>
00020 #include <qregexp.h>
00021
00022 #include <kconfig.h>
00023 #include <kdebug.h>
00024 #include <kglobal.h>
00025 #include <klocale.h>
00026 #include <kservice.h>
00027 #include <ktrader.h>
00028 #include <kapplication.h>
00029 #include <kdevplugin.h>
00030 #include "domutil.h"
00031
00032 #include "languageselectwidget.h"
00033 #include "plugincontroller.h"
00034
00035 class LangPluginItem : public QCheckListItem
00036 {
00037 public:
00038
00039 LangPluginItem( QListView * parent, QString const & name, QString const & label,
00040 QString const & info )
00041 : QCheckListItem( parent, label, QCheckListItem::CheckBox),
00042 _name( name ), _info( info )
00043 {}
00044
00045 QString info() { return _info; }
00046 QString name() { return _name; }
00047
00048 private:
00049 QString _name;
00050 QString _info;
00051 };
00052
00053
00054 LanguageSelectWidget::LanguageSelectWidget(QDomDocument &projectDom,
00055 QWidget *parent, const char *name)
00056 : QWidget(parent, name), m_projectDom(projectDom)
00057 {
00058 init();
00059 }
00060
00061 void LanguageSelectWidget::init()
00062 {
00063 QVBoxLayout *layout = new QVBoxLayout(this);
00064
00065 QGroupBox * groupBox1 = new QGroupBox( i18n("Additional Language Support"), this );
00066 groupBox1->setColumnLayout(0, Qt::Vertical );
00067 groupBox1->layout()->setSpacing( 6 );
00068 groupBox1->layout()->setMargin( 11 );
00069 QVBoxLayout * groupBox1Layout = new QVBoxLayout( groupBox1->layout() );
00070 groupBox1Layout->setAlignment( Qt::AlignTop );
00071
00072 _currentLanguage = new QLabel( "", groupBox1 );
00073
00074 _pluginList = new QListView( groupBox1 );
00075 _pluginList->setResizeMode( QListView::LastColumn );
00076 _pluginList->addColumn("");
00077 _pluginList->header()->hide();
00078
00079 groupBox1Layout->addWidget(_currentLanguage);
00080 groupBox1Layout->addWidget( _pluginList );
00081 layout->addWidget( groupBox1 );
00082
00083 QGroupBox * groupBox2 = new QGroupBox( i18n("Description"), this );
00084 groupBox2->setColumnLayout(0, Qt::Vertical );
00085 groupBox2->layout()->setSpacing( 6 );
00086 groupBox2->layout()->setMargin( 11 );
00087 QVBoxLayout * groupBox2Layout = new QVBoxLayout( groupBox2->layout() );
00088 groupBox2Layout->setAlignment( Qt::AlignTop );
00089
00090 _pluginDescription = new QLabel( groupBox2 );
00091 _pluginDescription->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
00092
00093 groupBox2Layout->addWidget( _pluginDescription );
00094
00095 layout->addWidget( groupBox2 );
00096
00097 connect( _pluginList, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( itemSelected( QListViewItem * ) ) );
00098
00099 readProjectConfig();
00100 }
00101
00102
00103 LanguageSelectWidget::~LanguageSelectWidget()
00104 {}
00105
00106 void LanguageSelectWidget::readProjectConfig()
00107 {
00108 KTrader::OfferList languageSupportOffers =
00109 KTrader::self()->query(QString::fromLatin1("KDevelop/LanguageSupport"),
00110 QString::fromLatin1("[X-KDevelop-Version] == %1"
00111 ).arg( KDEVELOP_PLUGIN_VERSION ));
00112
00113 QStringList languages = DomUtil::readListEntry(m_projectDom, "/general/secondaryLanguages", "language");
00114 QString language = DomUtil::readEntry(m_projectDom, "/general/primarylanguage");
00115 _currentLanguage->setText(i18n("Primary language is '%1'. Please select additional languages the project might contain.").arg(language));
00116
00117 for (KTrader::OfferList::ConstIterator it = languageSupportOffers.begin(); it != languageSupportOffers.end(); ++it)
00118 {
00119 QString la = (*it)->property("X-KDevelop-Language").toString();
00120 if (la == language)
00121 continue;
00122 LangPluginItem *item = new LangPluginItem( _pluginList, (*it)->property("X-KDevelop-Language").toString(), (*it)->genericName(), (*it)->comment() );
00123 item->setOn(languages.contains(la));
00124 }
00125
00126 QListViewItem * first = _pluginList->firstChild();
00127 if ( first ) {
00128 _pluginList->setSelected( first, true );
00129 }
00130 }
00131
00132 void LanguageSelectWidget::itemSelected( QListViewItem * item )
00133 {
00134 if ( !item ) return;
00135
00136 LangPluginItem * pitem = static_cast<LangPluginItem*>( item );
00137 _pluginDescription->setText( pitem->info() );
00138 }
00139
00140 void LanguageSelectWidget::saveProjectConfig()
00141 {
00142 QStringList languages;
00143
00144 QListViewItemIterator it( _pluginList );
00145 while ( it.current() )
00146 {
00147 LangPluginItem * item = static_cast<LangPluginItem*>( it.current() );
00148 if (item->isOn())
00149 {
00150 languages.append( item->name() );
00151 }
00152 ++it;
00153 }
00154
00155 DomUtil::writeListEntry(m_projectDom, "/general/secondaryLanguages", "language", languages);
00156 }
00157
00158
00159 void LanguageSelectWidget::accept()
00160 {
00161 saveProjectConfig();
00162 emit accepted();
00163 }
00164
00165 #include "languageselectwidget.moc"
This file is part of the documentation for KDevelop Version 3.1.2.