1 // SALOME TOOLSGUI : implementation of desktop "Tools" optioins
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : ToolsGUI_CatalogGeneratorDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "ToolsGUI_CatalogGeneratorDlg.h"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_FileDlg.h"
35 #include "QAD_MessageBox.h"
38 #include <qlineedit.h>
39 #include <qpushbutton.h>
41 #include <qgroupbox.h>
42 #include <qstringlist.h>
44 #include <qvalidator.h>
46 #include <OSD_Process.hxx>
47 #include <OSD_Path.hxx>
48 #include <TCollection_AsciiString.hxx>
49 #include <Standard_CString.hxx>
51 #define SPACING_SIZE 6
52 #define MARGIN_SIZE 11
53 #define MIN_EDIT_SIZE 250
55 //=================================================================================
56 // class : ToolsGUI_CatalogGeneratorDlg()
57 // purpose : Constructor
58 //=================================================================================
59 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
60 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 setName( "ToolsGUI_CatalogGeneratorDlg" );
65 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
66 setSizeGripEnabled( TRUE );
68 QGridLayout* aTopLayout = new QGridLayout(this);
69 aTopLayout->setMargin(MARGIN_SIZE);
70 aTopLayout->setSpacing(SPACING_SIZE);
72 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
73 filesGrp->setColumnLayout( 0, Qt::Vertical );
74 filesGrp->layout()->setSpacing( 0 );
75 filesGrp->layout()->setMargin( 0 );
76 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
77 filesGrpLayout->setAlignment( Qt::AlignTop );
78 filesGrpLayout->setSpacing( SPACING_SIZE );
79 filesGrpLayout->setMargin( MARGIN_SIZE );
81 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
82 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
83 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
84 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
85 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
88 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
89 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
90 // QFontMetrics fm(myBrowseIdlBtn->font());
91 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
92 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
94 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
95 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
96 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
97 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
98 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
99 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
101 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
102 supplGrp->setColumnLayout( 0, Qt::Vertical );
103 supplGrp->layout()->setSpacing( 0 );
104 supplGrp->layout()->setMargin( 0 );
105 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
106 supplGrpLayout->setAlignment( Qt::AlignTop );
107 supplGrpLayout->setSpacing( SPACING_SIZE );
108 supplGrpLayout->setMargin( MARGIN_SIZE );
110 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
111 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112 myAuthorEdit->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
114 OSD_Process aProcess;
115 myAuthorEdit->setText(aProcess.UserName().ToCString());
117 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
118 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119 myVersionEdit->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
120 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
121 myVersionEdit->setText(aList.last());
122 QDoubleValidator *validator = new QDoubleValidator(myVersionEdit);
123 myVersionEdit->setValidator(validator);
125 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
126 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
129 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
131 myCompName = new QLineEdit(supplGrp , "myCompName");
132 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
133 myCompName->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
135 myCompType = new QLineEdit(supplGrp , "myCompType");
136 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 myCompType->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
138 myCompType->setText("OTHER");
140 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
141 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 myCompMultiStd->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
143 myCompMultiStd->setText("1");
144 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
145 myCompMultiStd->setValidator(ivalidator);
147 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
148 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
149 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
150 supplGrpLayout->addWidget(myCompName,0,3);
151 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 0, 4);
152 supplGrpLayout->addWidget(myCompType,0,5);
153 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
154 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
155 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
156 supplGrpLayout->addWidget(myCompMultiStd,1,3);
157 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
158 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
159 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
162 QHBoxLayout* aBtnLayout = new QHBoxLayout;
163 aBtnLayout->setSpacing( SPACING_SIZE );
164 aBtnLayout->setMargin( 0 );
166 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
167 myApplyBtn->setAutoDefault( true );
168 myApplyBtn->setDefault( true );
169 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
170 myCloseBtn->setAutoDefault( true );
172 aBtnLayout->addWidget( myApplyBtn );
173 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
174 aBtnLayout->addWidget( myCloseBtn );
176 aTopLayout->addWidget( filesGrp, 0, 0 );
177 aTopLayout->addWidget( supplGrp, 1, 0 );
178 aTopLayout->addLayout( aBtnLayout, 2, 0 );
180 /* signals and slots connections */
181 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
182 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
183 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
184 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
185 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
186 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
187 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
192 //=================================================================================
193 // function : ~ToolsGUI_CatalogGeneratorDlg()
194 // purpose : destructor
195 //=================================================================================
196 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
200 //=================================================================================
201 // function : getIdlFile()
202 // purpose : gets IDL file name entered
203 //=================================================================================
204 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
206 return myIdlEdit->text().stripWhiteSpace();
209 //=================================================================================
210 // function : getXmlFile()
211 // purpose : gets XML file name entered
212 //=================================================================================
213 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
215 return myXmlEdit->text().stripWhiteSpace();
218 //=================================================================================
219 // function : getPngFile()
220 // purpose : gets PNG file name entered
221 //=================================================================================
222 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
224 return myPngEdit->text().stripWhiteSpace();
227 //=================================================================================
228 // function : getAuthor()
229 // purpose : gets author
230 //=================================================================================
231 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
233 return myAuthorEdit->text().stripWhiteSpace();
236 //=================================================================================
237 // function : getVersion()
238 // purpose : gets version number
239 //=================================================================================
240 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
242 return myVersionEdit->text().stripWhiteSpace();
245 //=================================================================================
246 // function : getCompName()
247 // purpose : gets name of the component
248 //=================================================================================
249 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
251 return myCompName->text().stripWhiteSpace();
254 //=================================================================================
255 // function : getCompType()
256 // purpose : gets type of the component
257 //=================================================================================
258 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
260 return myCompMultiStd->text().stripWhiteSpace();
262 //=================================================================================
263 // function : getComptype()
264 // purpose : gets type of the component
265 //=================================================================================
266 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
268 return myCompType->text().stripWhiteSpace();
271 //=================================================================================
272 // function : onBrowseBtnClicked()
273 // purpose : <...> (Browse) buttons slot
274 //=================================================================================
275 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
277 QPushButton* send = (QPushButton*)sender();
279 if ( send == myBrowseIdlBtn ) {
280 QString file = myIdlEdit->text().stripWhiteSpace();
281 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
283 tr("TOOLS_MEN_IMPORT_IDL"),
284 tr("TOOLS_MEN_IMPORT"),
286 if ( !file.isEmpty() ) {
287 myIdlEdit->setText(file);
290 else if ( send == myBrowseXmlBtn ) {
291 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
292 myXmlEdit->text().stripWhiteSpace(),
293 tr("TOOLS_MEN_EXPORT_XML"),
294 tr("TOOLS_MEN_EXPORT"),
296 if ( !file.isEmpty() ) {
297 myXmlEdit->setText(file);
299 } else if ( send == myBrowsePngBtn ) {
300 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
301 myXmlEdit->text().stripWhiteSpace(),
302 tr("TOOLS_MEN_IMPORT_PNG"),
303 tr("TOOLS_MEN_IMPORT"),
305 if ( !file.isEmpty() ) {
306 myPngEdit->setText(file);
313 //=================================================================================
314 // function : updateButtonState()
315 // purpose : Updates <OK> button's state
316 //=================================================================================
317 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
319 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
320 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
323 //=================================================================================
324 // function : onApply()
325 // purpose : <Apply> button slot, performs IDL->XML conversion
326 //=================================================================================
327 void ToolsGUI_CatalogGeneratorDlg::onApply()
329 QString XmlFile = getXmlFile();
330 QString IdlFile = getIdlFile();
331 QString Author = getAuthor();
332 QString Version = getVersion();
333 QString PngFile = getPngFile();
334 QString CompName = getCompName(); //gets component name
335 QString CompType = getCompType(); //gets component type
336 QString CompMultiStd = getCompMultiStd();
338 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
339 if ( !QFile::exists( IdlFile ) ) {
340 QAD_MessageBox::error1( this,
341 tr("TOOLS_ERR_ERROR"),
342 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
343 tr ("TOOLS_BUT_OK") );
346 QString command = QString( getenv( "SALOME_ROOT_DIR" ) ) + "/bin/runIDLparser -Wbcatalog=" + XmlFile;
347 if (!Author.isEmpty()) command += ",author=" + Author;
348 if (!Version.isEmpty()) command += ",version=" + Version;
349 if (!PngFile.isEmpty()) {
350 OSD_Path aPath((Standard_CString)PngFile.latin1());
351 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
352 command += QString(",icon=") + QString(aFile.ToCString());
354 if (!CompName.isEmpty()) command += ",name=" + CompName;
355 if (!CompType.isEmpty()) command += ",type=" + CompType;
356 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
357 command += " " + IdlFile;
358 MESSAGE( "shell command is : " << command );
360 res = system( ( char* )( command.latin1() ) );
362 MESSAGE( "work failed (system command result = " << res );
363 } else if (res == 217) {
364 MESSAGE( "shell exec failed (system command result = " << res );