• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Generic Shell
 

KDevelop Generic Shell

  • src
languageselectwidget.cpp
1 /***************************************************************************
2  * Copyright (C) 2003 by Harald Fernengel *
3  * harry@kdevelop.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  ***************************************************************************/
11 
12 #include <tqstring.h>
13 #include <tqvariant.h>
14 #include <tqheader.h>
15 #include <tqlabel.h>
16 #include <tqlayout.h>
17 #include <tqlistview.h>
18 #include <tqgroupbox.h>
19 #include <tqhbox.h>
20 #include <tqregexp.h>
21 
22 #include <tdeconfig.h>
23 #include <kdebug.h>
24 #include <tdeglobal.h>
25 #include <tdelocale.h>
26 #include <kservice.h>
27 #include <ktrader.h>
28 #include <tdeapplication.h>
29 #include <kdevplugin.h>
30 #include "domutil.h"
31 
32 #include "languageselectwidget.h"
33 #include "plugincontroller.h"
34 
35 class LangPluginItem : public TQCheckListItem
36 {
37 public:
38  // name - "Name", label - "GenericName", info - "Comment"
39  LangPluginItem( TQListView * parent, TQString const & name, TQString const & label,
40  TQString const & info )
41  : TQCheckListItem( parent, label, TQCheckListItem::CheckBox),
42  _name( name ), _info( info )
43  {}
44 
45  TQString info() { return _info; }
46  TQString name() { return _name; }
47 
48 private:
49  TQString _name;
50  TQString _info;
51 };
52 
53 
54 LanguageSelectWidget::LanguageSelectWidget(TQDomDocument &projectDom,
55  TQWidget *parent, const char *name)
56  : TQWidget(parent, name), m_projectDom(projectDom)
57 {
58  init();
59 }
60 
61 void LanguageSelectWidget::init()
62 {
63  TQVBoxLayout *layout = new TQVBoxLayout(this);
64 
65  TQGroupBox * groupBox1 = new TQGroupBox( i18n("Additional Language Support"), this );
66  groupBox1->setColumnLayout(0, Qt::Vertical );
67  groupBox1->layout()->setSpacing( 6 );
68  groupBox1->layout()->setMargin( 11 );
69  TQVBoxLayout * groupBox1Layout = new TQVBoxLayout( groupBox1->layout() );
70  groupBox1Layout->setAlignment( TQt::AlignTop );
71 
72  _currentLanguage = new TQLabel( "", groupBox1 );
73 
74  _pluginList = new TQListView( groupBox1 );
75  _pluginList->setResizeMode( TQListView::LastColumn );
76  _pluginList->addColumn("");
77  _pluginList->header()->hide();
78 
79  groupBox1Layout->addWidget(_currentLanguage);
80  groupBox1Layout->addWidget( _pluginList );
81  layout->addWidget( groupBox1 );
82 
83  TQGroupBox * groupBox2 = new TQGroupBox( i18n("Description"), this );
84  groupBox2->setColumnLayout(0, Qt::Vertical );
85  groupBox2->layout()->setSpacing( 6 );
86  groupBox2->layout()->setMargin( 11 );
87  TQVBoxLayout * groupBox2Layout = new TQVBoxLayout( groupBox2->layout() );
88  groupBox2Layout->setAlignment( TQt::AlignTop );
89 
90  _pluginDescription = new TQLabel( groupBox2 );
91  _pluginDescription->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignVCenter ) );
92 
93  groupBox2Layout->addWidget( _pluginDescription );
94 
95  layout->addWidget( groupBox2 );
96 
97  connect( _pluginList, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), this, TQT_SLOT( itemSelected( TQListViewItem * ) ) );
98 
99  readProjectConfig();
100 }
101 
102 
103 LanguageSelectWidget::~LanguageSelectWidget()
104 {}
105 
106 void LanguageSelectWidget::readProjectConfig()
107 {
108  TDETrader::OfferList languageSupportOffers =
109  TDETrader::self()->query(TQString::fromLatin1("TDevelop/LanguageSupport"),
110  TQString::fromLatin1("[X-TDevelop-Version] == %1"
111  ).arg( TDEVELOP_PLUGIN_VERSION ));
112 
113  TQStringList languages = DomUtil::readListEntry(m_projectDom, "/general/secondaryLanguages", "language");
114  TQString language = DomUtil::readEntry(m_projectDom, "/general/primarylanguage");
115  _currentLanguage->setText(i18n("Primary language is '%1'. Please select additional languages the project might contain.").arg(language));
116 
117  for (TDETrader::OfferList::ConstIterator it = languageSupportOffers.begin(); it != languageSupportOffers.end(); ++it)
118  {
119  TQString la = (*it)->property("X-TDevelop-Language").toString();
120  if (la == language)
121  continue;
122  LangPluginItem *item = new LangPluginItem( _pluginList, (*it)->property("X-TDevelop-Language").toString(), (*it)->genericName(), (*it)->comment() );
123  item->setOn(languages.contains(la));
124  }
125 
126  TQListViewItem * first = _pluginList->firstChild();
127  if ( first ) {
128  _pluginList->setSelected( first, true );
129  }
130 }
131 
132 void LanguageSelectWidget::itemSelected( TQListViewItem * item )
133 {
134  if ( !item ) return;
135 
136  LangPluginItem * pitem = static_cast<LangPluginItem*>( item );
137  _pluginDescription->setText( pitem->info() );
138 }
139 
140 void LanguageSelectWidget::saveProjectConfig()
141 {
142  TQStringList languages;
143 
144  TQListViewItemIterator it( _pluginList );
145  while ( it.current() )
146  {
147  LangPluginItem * item = static_cast<LangPluginItem*>( it.current() );
148  if (item->isOn())
149  {
150  languages.append( item->name() );
151  }
152  ++it;
153  }
154 
155  DomUtil::writeListEntry(m_projectDom, "/general/secondaryLanguages", "language", languages);
156 }
157 
158 
159 void LanguageSelectWidget::accept()
160 {
161  saveProjectConfig();
162  emit accepted();
163 }
164 
165 #include "languageselectwidget.moc"

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Generic Shell by doxygen 1.8.13
This website is maintained by Timothy Pearson.