Skip to content

Commit 4723aeb

Browse files
author
rugginoso
committed
Various enhancements into GRASS shell:
- Uses directly GRASS - Starts with a minimum size of 80x25 characters git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11118 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7e19431 commit 4723aeb

File tree

7 files changed

+51
-70
lines changed

7 files changed

+51
-70
lines changed

src/plugins/grass/qgsgrassshell.cpp

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsgrasstools.h"
2323
#include "qtermwidget/qtermwidget.h"
2424
#include "qgsapplication.h"
25+
#include "qgsgrass.h"
2526

2627
#include "qgsgrassshell.h"
2728

@@ -31,27 +32,30 @@ extern "C"
3132
}
3233

3334
QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const char *name )
34-
: QFrame( parent )
35+
: QFrame( parent ), mTools(tools), mTabWidget(parent)
3536
{
36-
mTools = tools;
37-
mTabWidget = parent;
38-
3937
QVBoxLayout *mainLayout = new QVBoxLayout( this );
4038
QTermWidget *mTerminal = new QTermWidget( 0, this );
4139
initTerminal( mTerminal );
42-
QPushButton *closeButton = new QPushButton( tr( "Close" ), this );
4340
QShortcut *pasteShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+V" ) ), mTerminal );
4441
QShortcut *copyShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+C" ) ), mTerminal );
4542

4643
mainLayout->addWidget( mTerminal );
47-
mainLayout->addWidget( closeButton );
4844
setLayout( mainLayout );
4945

50-
connect( closeButton, SIGNAL( clicked() ), this, SLOT( closeShell() ) );
5146
connect( mTerminal, SIGNAL( finished() ), this, SLOT( closeShell() ) );
5247
connect( pasteShortcut, SIGNAL( activated() ), mTerminal, SLOT( pasteClipboard() ) );
5348
connect( copyShortcut, SIGNAL( activated() ), mTerminal, SLOT( copyClipboard() ) );
5449

50+
// TODO: find a better way to manage the lockfile.
51+
mLockFilename = QgsGrass::lockFileParh();
52+
QFile::remove(mLockFilename + ".qgis");
53+
if (!QFile::rename(mLockFilename, mLockFilename + ".qgis"))
54+
{
55+
QMessageBox::warning(this, tr("Warning"), tr("Cannot rename the lock file %1").arg(mLockFilename));
56+
}
57+
58+
mTerminal->setSize(80, 25);
5559
mTerminal->startShellProgram();
5660
mTerminal->setFocus( Qt::MouseFocusReason );
5761
}
@@ -60,54 +64,34 @@ QgsGrassShell::~QgsGrassShell()
6064
{
6165
}
6266

63-
64-
/* TODO: Implement something that resizes the terminal without
65-
* crashes.
66-
void QgsGrassShell::resizeTerminal()
67-
{
68-
//mTerminal->setSize(80, 25);
69-
//mTerminal->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
70-
}
71-
*/
72-
7367
void QgsGrassShell::closeShell()
7468
{
7569
int index = mTabWidget->indexOf( this );
7670
mTabWidget->removeTab( index );
77-
delete this;
78-
}
7971

80-
void QgsGrassShell::initTerminal( QTermWidget *terminal )
81-
{
82-
QStringList args( "" );
83-
QStringList env( "" );
84-
// Set the shell program
85-
QString shell = ::getenv( "SHELL" );
86-
if ( shell.isEmpty() || shell.isNull() )
72+
// TODO: find a better way to manage the lockfile.
73+
if(!QFile::rename(mLockFilename + ".qgis", mLockFilename))
8774
{
88-
// if the shell isn't specified use the default one (/bin/bash)
89-
terminal->setShellProgram( shell );
75+
QMessageBox::warning(this, tr("Warning"), tr("Cannot rename the lock file %1").arg(mLockFilename));
9076
}
9177

92-
// Set shell program arguments
93-
QFileInfo shellInfo( shell );
94-
if ( shellInfo.fileName() == "bash" || shellInfo.fileName() == "sh" )
95-
{
96-
args << "--norc";
97-
}
98-
else if ( shellInfo.fileName() == "tcsh" || shellInfo.fileName() == "csh" )
99-
{
100-
args << "-f";
101-
}
102-
terminal->setArgs( args );
78+
this->deleteLater();
79+
}
10380

104-
// Set shell program enviroment variables
105-
env << "GRASS_MESSAGE_FORMAT=";
106-
env << "GRASS_UI_TERM=1";
107-
env << "GISRC_MODE_MEMORY";
108-
env << "PS1=GRASS > ";
81+
void QgsGrassShell::initTerminal( QTermWidget *terminal )
82+
{
83+
QStringList env("");
84+
QStringList args("");
85+
86+
terminal->setShellProgram("/usr/bin/grass64");
10987
env << "TERM=vt100";
110-
terminal->setEnvironment( env );
88+
env << "GISRC_MODE_MEMORY";
89+
90+
args << "-text";
91+
args << QString("%1/%2/%3").arg(QgsGrass::getDefaultGisdbase()).arg(QgsGrass::getDefaultLocation()).arg(QgsGrass::getDefaultMapset());
92+
93+
terminal->setArgs(args);
94+
terminal->setEnvironment(env);
11195

11296
// Look & Feel
11397
terminal->setScrollBarPosition( QTermWidget::ScrollBarRight );

src/plugins/grass/qgsgrassshell.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ class QgsGrassShell : public QFrame
2727
QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent = 0, const char *name = 0 );
2828
virtual ~QgsGrassShell();
2929

30-
/* TODO: Implement something that resizes the terminal without
31-
* crashes.
32-
public slots:
33-
void resizeTerminal();
34-
*/
35-
3630
private slots:
3731
void closeShell();
3832

@@ -42,4 +36,5 @@ class QgsGrassShell : public QFrame
4236
QTermWidget *mTerminal;
4337
QgsGrassTools *mTools;
4438
QTabWidget *mTabWidget;
39+
QString mLockFilename;
4540
};

src/plugins/grass/qgsgrasstools.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,6 @@ void QgsGrassTools::runModule( QString name )
150150
QWidget *m;
151151
if ( name == "shell" )
152152
{
153-
// Set history file
154-
QString mapsetPath = QgsGrass::getDefaultGisdbase() + "/"
155-
+ QgsGrass::getDefaultLocation() + "/"
156-
+ QgsGrass::getDefaultMapset();
157-
158-
// bash
159-
QString hist = "HISTFILE=" + mapsetPath + "/.bash_history";
160-
char *histChar = new char[hist.length()+1];
161-
strcpy( histChar, hist.toAscii().constData() );
162-
putenv( histChar );
163-
164-
// csh/tcsh
165-
#ifndef WIN32
166-
hist = "histfile=" + mapsetPath + "/.history";
167-
histChar = new char[hist.length()+1];
168-
strcpy( histChar, hist.toAscii().constData() );
169-
putenv( histChar );
170-
#endif
171-
172153
#ifdef WIN32
173154
if ( !QProcess::startDetached( getenv( "COMSPEC" ) ) )
174155
{

src/plugins/grass/qtermwidget/qtermwidget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ void QTermWidget::setFlowControlWarningEnabled(bool enabled)
259259
}
260260
}
261261

262+
QSize QTermWidget::minimumSizeHint() const
263+
{
264+
return m_impl->m_terminalDisplay->sizeHint();
265+
}
266+
267+
QSize QTermWidget::sizeHint() const
268+
{
269+
return m_impl->m_terminalDisplay->sizeHint();
270+
}
271+
262272
void QTermWidget::setEnvironment(const QStringList& environment)
263273
{
264274
m_impl->m_session->setEnvironment(environment);

src/plugins/grass/qtermwidget/qtermwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class QTermWidget : public QWidget
106106
*/
107107
void setFlowControlWarningEnabled(bool enabled);
108108

109+
QSize minimumSizeHint() const;
110+
QSize sizeHint() const;
111+
109112
signals:
110113
void finished();
111114
void receivedData(const QString &data);

src/providers/grass/qgsgrass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,3 +1081,8 @@ bool GRASS_EXPORT QgsGrass::isMapset( QString path )
10811081

10821082
return false;
10831083
}
1084+
1085+
QString GRASS_EXPORT QgsGrass::lockFileParh()
1086+
{
1087+
return mMapsetLock;
1088+
}

src/providers/grass/qgsgrass.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class QgsGrass
151151
// ! test if the directory is mapset
152152
static GRASS_EXPORT bool isMapset( QString path );
153153

154+
// ! Get the lock file
155+
static GRASS_EXPORT QString lockFileParh();
156+
154157
//! Library version
155158
static GRASS_EXPORT int versionMajor();
156159
static GRASS_EXPORT int versionMinor();

0 commit comments

Comments
 (0)