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

KDevelop Generic Shell

  • src
generalinfowidget.cpp
1 /***************************************************************************
2  * Copyright (C) 2002 by Yann Hodique *
3  * Yann.Hodique@lifl.fr *
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 #include <klineedit.h>
12 #include <tqtextedit.h>
13 #include <tqcombobox.h>
14 #include <tqlabel.h>
15 #include <tqfileinfo.h>
16 #include <tqdir.h>
17 
18 #include <kurl.h>
19 #include <tdelocale.h>
20 #include <kiconloader.h>
21 #include <kcharsets.h>
22 #include <tqregexp.h>
23 #include <tdemessagebox.h>
24 
25 #include "generalinfowidget.h"
26 #include "generalinfowidget.moc"
27 #include "domutil.h"
28 #include "projectmanager.h"
29 
30 TQString makeRelativePath(const TQString& fromPath, const TQString& toPath);
31 
32 GeneralInfoWidget::GeneralInfoWidget(TQDomDocument &projectDom, TQWidget *parent, const char *name)
33  : GeneralInfoWidgetBase(parent, name), m_projectDom(projectDom) {
34 
35  connect(project_directory_edit, TQT_SIGNAL(textChanged(const TQString&)),
36  this, TQT_SLOT(slotProjectDirectoryChanged(const TQString&)));
37  connect(project_directory_combo, TQT_SIGNAL(activated(int)),
38  this, TQT_SLOT(slotProjectDirectoryComboChanged()));
39  readConfig();
40 }
41 
42 
43 
44 GeneralInfoWidget::~GeneralInfoWidget() {}
45 
46 void GeneralInfoWidget::readConfig() {
47  if(DomUtil::readBoolEntry(m_projectDom,"/general/absoluteprojectpath",false))
48  this->project_directory_combo->setCurrentItem(0);
49  else
50  this->project_directory_combo->setCurrentItem(1);
51  this->project_directory_edit->setText(DomUtil::readEntry(m_projectDom,"/general/projectdirectory","."));
52  this->author_edit->setText(DomUtil::readEntry(m_projectDom,"/general/author"));
53  this->email_edit->setText(DomUtil::readEntry(m_projectDom,"/general/email"));
54  this->version_edit->setText(DomUtil::readEntry(m_projectDom,"/general/version"));
55  this->description_edit->setText(DomUtil::readEntry(m_projectDom,"/general/description"));
56 
57  TQStringList encodings;
58  encodings << i18n("Use global editor settings");
59  encodings += TDEGlobal::charsets()->descriptiveEncodingNames();
60  TQStringList::const_iterator it = encodings.constBegin();
61  while ( it != encodings.constEnd() )
62  {
63  encoding_combo->insertItem( *it );
64  ++it;
65  }
66  encoding_combo->setCurrentItem( 0 );
67 
68 // const TQString DefaultEncoding = TDEGlobal::charsets()->encodingForName( DomUtil::readEntry( m_projectDom, "/general/defaultencoding", TQString() ) );
69  const TQString DefaultEncoding = DomUtil::readEntry( m_projectDom, "/general/defaultencoding", TQString() );
70  for ( int i = 0; i < encoding_combo->count(); i++ )
71  {
72  if ( TDEGlobal::charsets()->encodingForName( encoding_combo->text( i ) ) == DefaultEncoding )
73  {
74  encoding_combo->setCurrentItem( i );
75  break;
76  }
77  }
78 
79 }
90 void GeneralInfoWidget::configureinUpdateVersion( TQString configureinpath, TQString newVersion )
91 {
92  TQFile configurein(configureinpath);
93 
94  if ( !configurein.open( IO_ReadOnly ) ){
95  KMessageBox::error(this, i18n("Could not open %1 for reading.").arg(configureinpath));
96  return;
97  }
98 
99  TQTextStream stream( &configurein);
100  TQStringList list;
101 
102  // Options for version:
103 
104  // we ignore old AC_INIT that had no version..
105  // only match the if there is a comma and at least two args..
106  // AC_INIT (package, version, [bug-report], [tarname])
107  TQRegExp ac_init("^AC_INIT\\s*\\(\\s*([^,]+),([^,\\)]+)(.*)");
108 
109  // AM_INIT_AUTOMAKE([OPTIONS])
110  // example: AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
111  TQRegExp am_autoSpace("^AM_INIT_AUTOMAKE\\s{0,}\\(\\s{0,}([\\[\\s]{0,}[^\\s]+)\\s+([^\\s\\)\\]]+)(.*)");
112 
113  // AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
114  TQRegExp am_autoComma("^AM_INIT_AUTOMAKE\\s*\\(\\s*([^,]+),([^,\\)]+)(.*)");
115 
116  // look for version in a define.
117  // AC_DEFINE(VERSION, "5.6")
118  TQRegExp ac_define("^AC_DEFINE\\s*\\(");
119  TQRegExp version("(\\bversion\\b)");
120  version.setCaseSensitive(FALSE);
121 
122  while ( !stream.eof() ) {
123  TQString line = stream.readLine();
124  if ( ac_init.search(line) >= 0){
125  line = "AC_INIT(" + ac_init.cap(1).stripWhiteSpace();
126  line += ", ";
127  line += newVersion;
128  line += ac_init.cap(3).stripWhiteSpace();
129  }
130  else if ( am_autoComma.search(line) >= 0 ){
131  line="AM_INIT_AUTOMAKE(";
132  line += am_autoComma.cap(1).stripWhiteSpace();
133  line += ", ";
134  line += newVersion;
135  line += am_autoComma.cap(3).stripWhiteSpace();
136  }
137  else if ( am_autoSpace.search(line) >= 0 ){
138  line = "AM_INIT_AUTOMAKE(" + am_autoSpace.cap(1).stripWhiteSpace();
139  line += " ";
140  line += newVersion;
141  line += " ";
142  line += am_autoSpace.cap(3).stripWhiteSpace();
143  }
144  else if ( ac_define.search(line) >=0 && version.search(line) >=0) {
145  // replace version in: AC_DEFINE(VERSION,"0.1")
146  line="AC_DEFINE(" + version.cap(1).stripWhiteSpace()+", \"" + newVersion +"\")";
147  }
148  list.push_back(line);
149  }
150  configurein.close();
151 
152  // write our changes..
153  TQFile configureout(configureinpath);
154  if ( !configureout.open( IO_WriteOnly ) ){
155  KMessageBox::error(this, i18n("Could not open %1 for writing.").arg(configureinpath));
156  return ;
157  }
158  TQTextStream output( &configureout);
159  for(TQStringList::iterator iter = list.begin();iter!=list.end();iter++){
160  output << (*iter) <<"\n";
161  }
162  configureout.close();
163 }
164 
165 void GeneralInfoWidget::writeConfig() {
166  DomUtil::writeEntry(m_projectDom,"/general/projectdirectory",project_directory_edit->text());
167  DomUtil::writeBoolEntry(m_projectDom,"/general/absoluteprojectpath",isProjectDirectoryAbsolute());
168  DomUtil::writeEntry(m_projectDom,"/general/email",email_edit->text());
169  DomUtil::writeEntry(m_projectDom,"/general/author",author_edit->text());
170  DomUtil::writeEntry(m_projectDom,"/general/email",email_edit->text());
171  if ( DomUtil::readEntry(m_projectDom,"/general/version") != version_edit->text() && !DomUtil::elementByPath( m_projectDom, "/kdevautoproject").isNull() ){
172  // update the configure.in.in, configure.in or configure.ac file.
173  TQFile inInFile(projectDirectory() + "/configure.in.in");
174  TQFile inFile(projectDirectory() + "/configure.in");
175  TQFile acFile(projectDirectory() + "/configure.ac");
176  if ( inInFile.exists()){
177  configureinUpdateVersion( inInFile.name(), version_edit->text() );
178  }
179  if ( inFile.exists()){
180  configureinUpdateVersion( inFile.name(), version_edit->text() );
181  }
182  if (acFile.exists()){
183  configureinUpdateVersion( acFile.name(), version_edit->text() );
184  }
185  if (! inInFile.exists()&& !inFile.exists() && !acFile.exists()) {
186  KMessageBox::error(this, i18n("Could not find configure.in.in, configure.in or configure.ac to update the project version."));
187  }
188  }
189  DomUtil::writeEntry(m_projectDom,"/general/version",version_edit->text());
190  DomUtil::writeEntry(m_projectDom,"/general/description",description_edit->text());
191 
192  TQString DefaultEncoding = TQString();
193  if ( encoding_combo->currentItem() > 0 )
194  {
195  DefaultEncoding = TDEGlobal::charsets()->encodingForName( encoding_combo->currentText() );
196  }
197  DomUtil::writeEntry( m_projectDom, "/general/defaultencoding", DefaultEncoding );
198 }
199 
200 void GeneralInfoWidget::accept() {
201  writeConfig();
202 }
203 
204 bool GeneralInfoWidget::isProjectDirectoryAbsolute() {
205  return project_directory_combo->currentItem() == 0;
206 }
207 
208 TQString GeneralInfoWidget::projectDirectory() {
209  return ProjectManager::projectDirectory( project_directory_edit->text(), isProjectDirectoryAbsolute() );
210 }
211 
212 void GeneralInfoWidget::slotProjectDirectoryChanged( const TQString& text ) {
213  if(text.isEmpty())
214  {
215  setProjectDirectoryError(i18n("Please enter a path."));
216  }
217  else if(isProjectDirectoryAbsolute() && text[0] != '/')
218  {
219  setProjectDirectoryError(
220  i18n("'%1' is not an absolute path.").arg(
221  project_directory_edit->text()));
222  }
223  else if(!isProjectDirectoryAbsolute() && text[0] == '/')
224  {
225  setProjectDirectoryError(
226  i18n("'%1' is not a relative path.").arg(
227  project_directory_edit->text()));
228  }
229  else
230  {
231  TQFileInfo info(projectDirectory());
232  if(!info.exists())
233  setProjectDirectoryError(
234  i18n("'%1' does not exist.").arg(
235  project_directory_edit->text()));
236  else if(!info.isDir())
237  setProjectDirectoryError(
238  i18n("'%1' is not a directory.").arg(
239  project_directory_edit->text()));
240  else
241  setProjectDirectorySuccess();
242  }
243 }
244 
245 void GeneralInfoWidget::slotProjectDirectoryComboChanged() {
246  TQString text = project_directory_edit->text();
247  if(isProjectDirectoryAbsolute() && text[0] != '/' )
248  project_directory_edit->setText(ProjectManager::projectDirectory(text,false));
249  else if(!isProjectDirectoryAbsolute() && text[0] == '/')
250  {
251  project_directory_edit->setText(KURL(ProjectManager::getInstance()->projectFile(), text).url());
252  }
253 }
254 
255 void GeneralInfoWidget::setProjectDirectoryError( const TQString& error ) {
256  project_directory_diagnostic_icon->setPixmap(SmallIcon("no"));
257  project_directory_diagnostic_label->setText( error );
258 }
259 
260 void GeneralInfoWidget::setProjectDirectorySuccess() {
261  project_directory_diagnostic_icon->setPixmap(SmallIcon("ok"));
262  if(isProjectDirectoryAbsolute())
263  project_directory_diagnostic_label->setText(
264  i18n("'%1' is a valid project directory.").arg(projectDirectory()));
265  else
266  project_directory_diagnostic_label->setText(
267  i18n("'%1' is a valid project directory.").arg(projectDirectory()));
268 }
269 
270 TQString makeRelativePath(const TQString& fromPath, const TQString& toPath)
271 {
272  if ( fromPath == toPath )
273  return ".";
274 
275  TQStringList fromDirs = TQStringList::split( '/', fromPath );
276  TQStringList toDirs = TQStringList::split( '/', toPath );
277  TQStringList::iterator fromIt = fromDirs.begin();
278  TQStringList::iterator toIt = toDirs.begin();
279 
280  TQString relative;
281 
282  for ( ; (*fromIt) == (*toIt); ++fromIt, ++toIt )
283  ;
284 
285  for ( ; fromIt != fromDirs.end(); ++fromIt )
286  relative += "../";
287 
288  for ( ; toIt != toDirs.end(); ++toIt )
289  relative += *toIt + "/";
290 
291  return relative;
292 }

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.