Skip to content

Commit

Permalink
Various enhancements into GRASS shell:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
rugginoso committed Jul 20, 2009
1 parent 7e19431 commit 4723aeb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 70 deletions.
74 changes: 29 additions & 45 deletions src/plugins/grass/qgsgrassshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgsgrasstools.h"
#include "qtermwidget/qtermwidget.h"
#include "qgsapplication.h"
#include "qgsgrass.h"

#include "qgsgrassshell.h"

Expand All @@ -31,27 +32,30 @@ extern "C"
}

QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const char *name )
: QFrame( parent )
: QFrame( parent ), mTools(tools), mTabWidget(parent)
{
mTools = tools;
mTabWidget = parent;

QVBoxLayout *mainLayout = new QVBoxLayout( this );
QTermWidget *mTerminal = new QTermWidget( 0, this );
initTerminal( mTerminal );
QPushButton *closeButton = new QPushButton( tr( "Close" ), this );
QShortcut *pasteShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+V" ) ), mTerminal );
QShortcut *copyShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+C" ) ), mTerminal );

mainLayout->addWidget( mTerminal );
mainLayout->addWidget( closeButton );
setLayout( mainLayout );

connect( closeButton, SIGNAL( clicked() ), this, SLOT( closeShell() ) );
connect( mTerminal, SIGNAL( finished() ), this, SLOT( closeShell() ) );
connect( pasteShortcut, SIGNAL( activated() ), mTerminal, SLOT( pasteClipboard() ) );
connect( copyShortcut, SIGNAL( activated() ), mTerminal, SLOT( copyClipboard() ) );

// TODO: find a better way to manage the lockfile.
mLockFilename = QgsGrass::lockFileParh();
QFile::remove(mLockFilename + ".qgis");
if (!QFile::rename(mLockFilename, mLockFilename + ".qgis"))
{
QMessageBox::warning(this, tr("Warning"), tr("Cannot rename the lock file %1").arg(mLockFilename));
}

mTerminal->setSize(80, 25);
mTerminal->startShellProgram();
mTerminal->setFocus( Qt::MouseFocusReason );
}
Expand All @@ -60,54 +64,34 @@ QgsGrassShell::~QgsGrassShell()
{
}


/* TODO: Implement something that resizes the terminal without
* crashes.
void QgsGrassShell::resizeTerminal()
{
//mTerminal->setSize(80, 25);
//mTerminal->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}
*/

void QgsGrassShell::closeShell()
{
int index = mTabWidget->indexOf( this );
mTabWidget->removeTab( index );
delete this;
}

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

// Set shell program arguments
QFileInfo shellInfo( shell );
if ( shellInfo.fileName() == "bash" || shellInfo.fileName() == "sh" )
{
args << "--norc";
}
else if ( shellInfo.fileName() == "tcsh" || shellInfo.fileName() == "csh" )
{
args << "-f";
}
terminal->setArgs( args );
this->deleteLater();
}

// Set shell program enviroment variables
env << "GRASS_MESSAGE_FORMAT=";
env << "GRASS_UI_TERM=1";
env << "GISRC_MODE_MEMORY";
env << "PS1=GRASS > ";
void QgsGrassShell::initTerminal( QTermWidget *terminal )
{
QStringList env("");
QStringList args("");

terminal->setShellProgram("/usr/bin/grass64");
env << "TERM=vt100";
terminal->setEnvironment( env );
env << "GISRC_MODE_MEMORY";

args << "-text";
args << QString("%1/%2/%3").arg(QgsGrass::getDefaultGisdbase()).arg(QgsGrass::getDefaultLocation()).arg(QgsGrass::getDefaultMapset());

terminal->setArgs(args);
terminal->setEnvironment(env);

// Look & Feel
terminal->setScrollBarPosition( QTermWidget::ScrollBarRight );
Expand Down
7 changes: 1 addition & 6 deletions src/plugins/grass/qgsgrassshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class QgsGrassShell : public QFrame
QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent = 0, const char *name = 0 );
virtual ~QgsGrassShell();

/* TODO: Implement something that resizes the terminal without
* crashes.
public slots:
void resizeTerminal();
*/

private slots:
void closeShell();

Expand All @@ -42,4 +36,5 @@ class QgsGrassShell : public QFrame
QTermWidget *mTerminal;
QgsGrassTools *mTools;
QTabWidget *mTabWidget;
QString mLockFilename;
};
19 changes: 0 additions & 19 deletions src/plugins/grass/qgsgrasstools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,6 @@ void QgsGrassTools::runModule( QString name )
QWidget *m;
if ( name == "shell" )
{
// Set history file
QString mapsetPath = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset();

// bash
QString hist = "HISTFILE=" + mapsetPath + "/.bash_history";
char *histChar = new char[hist.length()+1];
strcpy( histChar, hist.toAscii().constData() );
putenv( histChar );

// csh/tcsh
#ifndef WIN32
hist = "histfile=" + mapsetPath + "/.history";
histChar = new char[hist.length()+1];
strcpy( histChar, hist.toAscii().constData() );
putenv( histChar );
#endif

#ifdef WIN32
if ( !QProcess::startDetached( getenv( "COMSPEC" ) ) )
{
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/grass/qtermwidget/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ void QTermWidget::setFlowControlWarningEnabled(bool enabled)
}
}

QSize QTermWidget::minimumSizeHint() const
{
return m_impl->m_terminalDisplay->sizeHint();
}

QSize QTermWidget::sizeHint() const
{
return m_impl->m_terminalDisplay->sizeHint();
}

void QTermWidget::setEnvironment(const QStringList& environment)
{
m_impl->m_session->setEnvironment(environment);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/grass/qtermwidget/qtermwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class QTermWidget : public QWidget
*/
void setFlowControlWarningEnabled(bool enabled);

QSize minimumSizeHint() const;
QSize sizeHint() const;

signals:
void finished();
void receivedData(const QString &data);
Expand Down
5 changes: 5 additions & 0 deletions src/providers/grass/qgsgrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,3 +1081,8 @@ bool GRASS_EXPORT QgsGrass::isMapset( QString path )

return false;
}

QString GRASS_EXPORT QgsGrass::lockFileParh()
{
return mMapsetLock;
}
3 changes: 3 additions & 0 deletions src/providers/grass/qgsgrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class QgsGrass
// ! test if the directory is mapset
static GRASS_EXPORT bool isMapset( QString path );

// ! Get the lock file
static GRASS_EXPORT QString lockFileParh();

//! Library version
static GRASS_EXPORT int versionMajor();
static GRASS_EXPORT int versionMinor();
Expand Down

0 comments on commit 4723aeb

Please sign in to comment.