KDevelop API Documentation

generalinfowidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002 by Yann Hodique                                    *
00003  *   Yann.Hodique@lifl.fr                                                  *
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 #include <qlineedit.h>
00012 #include <qtextedit.h>
00013 #include <qcombobox.h>
00014 #include <qlabel.h>
00015 #include <qfileinfo.h>
00016 #include <qdir.h>
00017 
00018 #include <kurl.h>
00019 #include <klocale.h>
00020 #include <kiconloader.h>
00021 
00022 #include "generalinfowidget.h"
00023 #include "generalinfowidget.moc"
00024 #include "domutil.h"
00025 #include "projectmanager.h"
00026 
00027 QString makeRelativePath(const QString& fromPath, const QString& toPath);
00028 
00029 GeneralInfoWidget::GeneralInfoWidget(QDomDocument &projectDom, QWidget *parent, const char *name)
00030         : GeneralInfoWidgetBase(parent, name), m_projectDom(projectDom) {
00031 
00032     connect(project_directory_edit, SIGNAL(textChanged(const QString&)),
00033             this, SLOT(slotProjectDirectoryChanged(const QString&)));
00034     connect(project_directory_combo, SIGNAL(activated(int)),
00035             this, SLOT(slotProjectDirectoryComboChanged()));
00036     readConfig();
00037 }
00038 
00039 
00040 
00041 GeneralInfoWidget::~GeneralInfoWidget() {}
00042 
00043 void GeneralInfoWidget::readConfig() {
00044     if(DomUtil::readBoolEntry(m_projectDom,"/general/absoluteprojectpath",false))
00045         this->project_directory_combo->setCurrentItem(0);
00046     else
00047         this->project_directory_combo->setCurrentItem(1);
00048     this->project_directory_edit->setText(DomUtil::readEntry(m_projectDom,"/general/projectdirectory","."));
00049     this->author_edit->setText(DomUtil::readEntry(m_projectDom,"/general/author"));
00050     this->email_edit->setText(DomUtil::readEntry(m_projectDom,"/general/email"));
00051     this->version_edit->setText(DomUtil::readEntry(m_projectDom,"/general/version"));
00052     this->description_edit->setText(DomUtil::readEntry(m_projectDom,"/general/description"));
00053 }
00054 
00055 void GeneralInfoWidget::writeConfig() {
00056     DomUtil::writeEntry(m_projectDom,"/general/projectdirectory",project_directory_edit->text());
00057     DomUtil::writeBoolEntry(m_projectDom,"/general/absoluteprojectpath",isProjectDirectoryAbsolute());
00058     DomUtil::writeEntry(m_projectDom,"/general/email",email_edit->text());
00059     DomUtil::writeEntry(m_projectDom,"/general/author",author_edit->text());
00060     DomUtil::writeEntry(m_projectDom,"/general/email",email_edit->text());
00061     DomUtil::writeEntry(m_projectDom,"/general/version",version_edit->text());
00062     DomUtil::writeEntry(m_projectDom,"/general/description",description_edit->text());
00063 }
00064 
00065 void GeneralInfoWidget::accept() {
00066     writeConfig();
00067 }
00068 
00069 bool GeneralInfoWidget::isProjectDirectoryAbsolute() {
00070     return project_directory_combo->currentItem() == 0;
00071 }
00072 
00073 QString GeneralInfoWidget::projectDirectory() {
00074     return ProjectManager::projectDirectory( project_directory_edit->text(), isProjectDirectoryAbsolute() );
00075 }
00076 
00077 void GeneralInfoWidget::slotProjectDirectoryChanged( const QString& text ) {
00078     if(text.isEmpty())
00079     {
00080        setProjectDirectoryError(i18n("Please enter a path."));
00081     }
00082     else if(isProjectDirectoryAbsolute() && text[0] != '/')
00083     {
00084        setProjectDirectoryError(
00085            i18n("'%1' is not an absolute path.").arg(
00086                project_directory_edit->text()));
00087     }
00088     else if(!isProjectDirectoryAbsolute() && text[0] == '/')
00089     {
00090        setProjectDirectoryError(
00091            i18n("'%1' is not a relative path.").arg(
00092                project_directory_edit->text()));
00093     }
00094     else
00095     {
00096         QFileInfo info(projectDirectory());
00097         if(!info.exists())
00098            setProjectDirectoryError(
00099                i18n("'%1' does not exist.").arg(
00100                    project_directory_edit->text()));
00101         else if(!info.isDir())
00102            setProjectDirectoryError(
00103                i18n("'%1' is not a directory.").arg(
00104                    project_directory_edit->text()));
00105         else
00106            setProjectDirectorySuccess();
00107     }
00108 }
00109 
00110 void GeneralInfoWidget::slotProjectDirectoryComboChanged() {
00111     QString text = project_directory_edit->text();
00112     if(isProjectDirectoryAbsolute() && text[0] != '/' )
00113         project_directory_edit->setText(ProjectManager::projectDirectory(text,false));
00114     else if(!isProjectDirectoryAbsolute() && text[0] == '/')
00115     {
00116         project_directory_edit->setText(KURL(ProjectManager::getInstance()->projectFile(), text).url());
00117     }
00118 }
00119 
00120 void GeneralInfoWidget::setProjectDirectoryError( const QString& error ) {
00121     project_directory_diagnostic_icon->setPixmap(SmallIcon("no"));
00122     project_directory_diagnostic_label->setText( error );
00123 }
00124 
00125 void GeneralInfoWidget::setProjectDirectorySuccess() {
00126     project_directory_diagnostic_icon->setPixmap(SmallIcon("ok"));
00127     if(isProjectDirectoryAbsolute())
00128         project_directory_diagnostic_label->setText(
00129             i18n("'%1' is a valid project directory.").arg(projectDirectory()));
00130     else
00131         project_directory_diagnostic_label->setText(
00132             i18n("'%1' is a valid project directory.").arg(projectDirectory()));
00133 }
00134 
00135 QString makeRelativePath(const QString& fromPath, const QString& toPath)
00136 {
00137     if ( fromPath == toPath )
00138         return ".";
00139 
00140     QStringList fromDirs = QStringList::split( '/', fromPath );
00141     QStringList toDirs   = QStringList::split( '/', toPath );
00142     QStringList::iterator fromIt = fromDirs.begin();
00143     QStringList::iterator toIt   = toDirs.begin();
00144 
00145     QString relative;
00146 
00147     for ( ; (*fromIt) == (*toIt); ++fromIt, ++toIt )
00148         ;
00149 
00150     for ( ; fromIt != fromDirs.end(); ++fromIt )
00151         relative += "../";
00152 
00153     for ( ; toIt != toDirs.end(); ++toIt )
00154         relative += *toIt + "/";
00155 
00156     return relative;
00157 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:58 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003