1 /***************************************************************************
2         File                 : ScriptingLangDialog.cpp
3         Project              : SciDAVis
4 --------------------------------------------------------------------
5         Copyright            : (C) 2006 by Knut Franke, Ion Vasilief
6         Email (use @ for *)  : knut.franke*gmx.de, ion_vasilief*yahoo.fr
7         Description          : Dialog for changing the current scripting
8                                language
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  *                                                                         *
14  *  This program is free software; you can redistribute it and/or modify   *
15  *  it under the terms of the GNU General Public License as published by   *
16  *  the Free Software Foundation; either version 2 of the License, or      *
17  *  (at your option) any later version.                                    *
18  *                                                                         *
19  *  This program is distributed in the hope that it will be useful,        *
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
22  *  GNU General Public License for more details.                           *
23  *                                                                         *
24  *   You should have received a copy of the GNU General Public License     *
25  *   along with this program; if not, write to the Free Software           *
26  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
27  *   Boston, MA  02110-1301  USA                                           *
28  *                                                                         *
29  ***************************************************************************/
30 #include "ScriptingLangDialog.h"
31 #include "ApplicationWindow.h"
32 
33 #include <QListWidget>
34 #include <QPushButton>
35 #include <QLayout>
36 #include <QMessageBox>
37 
ScriptingLangDialog(ScriptingEnv * env,ApplicationWindow * parent,Qt::WindowFlags fl)38 ScriptingLangDialog::ScriptingLangDialog(ScriptingEnv *env, ApplicationWindow *parent,
39                                          Qt::WindowFlags fl)
40     : QDialog(parent, fl), scripted(env)
41 {
42     setWindowTitle(tr("Select scripting language"));
43 
44     langList = new QListWidget(this);
45 
46     btnOK = new QPushButton(tr("OK"));
47     btnCancel = new QPushButton(tr("Cancel"));
48 
49     QHBoxLayout *hbox1 = new QHBoxLayout();
50     hbox1->addStretch();
51     hbox1->addWidget(btnOK);
52     hbox1->addWidget(btnCancel);
53 
54     QVBoxLayout *vl = new QVBoxLayout(this);
55     vl->addWidget(langList);
56     vl->addLayout(hbox1);
57 
58     connect(btnOK, SIGNAL(clicked()), this, SLOT(accept()));
59     connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
60     connect(langList, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(accept()));
61 
62     updateLangList();
63 }
64 
updateLangList()65 void ScriptingLangDialog::updateLangList()
66 {
67     langList->clear();
68     langList->insertItems(0, ScriptingLangManager::languages());
69     QListWidgetItem *current =
70             langList->findItems(scriptEnv->objectName(), Qt::MatchExactly).first();
71     if (current)
72         langList->setCurrentItem(current);
73 }
74 
accept()75 void ScriptingLangDialog::accept()
76 {
77     ApplicationWindow *app = (ApplicationWindow *)parent();
78     if (app->setScriptingLang(langList->currentItem()->text()))
79         close();
80     else
81         QMessageBox::critical(this, tr("Scripting Error"),
82                               tr("Scripting language \"%1\" failed to initialize.")
83                                       .arg(langList->currentItem()->text()));
84 }
85