annotate hgrunner.cpp @ 291:2e34e7ee7baf more_information_dialog

Make several operations use the new more-information dialog
author Chris Cannam
date Mon, 21 Feb 2011 15:55:39 +0000
parents 0dbfea0099ca
children dff8ec43c86d
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
jtkorhonen@0 17
jtkorhonen@0 18 #include "hgrunner.h"
Chris@62 19 #include "common.h"
Chris@57 20 #include "debug.h"
Chris@240 21 #include "settingsdialog.h"
Chris@50 22
Chris@50 23 #include <QPushButton>
Chris@50 24 #include <QListWidget>
Chris@50 25 #include <QDialog>
Chris@50 26 #include <QLabel>
Chris@50 27 #include <QVBoxLayout>
Chris@62 28 #include <QSettings>
Chris@75 29 #include <QInputDialog>
Chris@188 30 #include <QTemporaryFile>
Chris@161 31 #include <QDir>
jtkorhonen@0 32
Chris@43 33 #include <iostream>
Chris@75 34 #include <errno.h>
Chris@75 35 #include <stdio.h>
Chris@111 36 #include <stdlib.h>
jtkorhonen@0 37
Chris@76 38 #ifndef Q_OS_WIN32
Chris@111 39 #include <unistd.h>
Chris@113 40 #include <termios.h>
Chris@111 41 #include <fcntl.h>
Chris@80 42 #endif
Chris@76 43
Chris@172 44 HgRunner::HgRunner(QString myDirPath, QWidget * parent) :
Chris@172 45 QProgressBar(parent),
Chris@172 46 m_myDirPath(myDirPath)
jtkorhonen@0 47 {
Chris@113 48 m_proc = 0;
Chris@84 49
Chris@239 50 // Always unbundle the extension: even if it already exists (in
Chris@239 51 // case we're upgrading) and even if we're not going to use it (so
Chris@239 52 // that it's available in case someone wants to use it later,
Chris@239 53 // e.g. to fix a malfunctioning setup). But the path we actually
Chris@239 54 // prefer is the one in the settings first, if it exists; then the
Chris@239 55 // unbundled one; then anything in the path if for some reason
Chris@239 56 // unbundling failed
Chris@239 57 unbundleExtension();
Chris@239 58
jtkorhonen@0 59 setTextVisible(false);
jtkorhonen@0 60 setVisible(false);
Chris@84 61 m_isRunning = false;
jtkorhonen@0 62 }
jtkorhonen@0 63
jtkorhonen@0 64 HgRunner::~HgRunner()
jtkorhonen@0 65 {
Chris@111 66 closeTerminal();
Chris@120 67 if (m_proc) {
Chris@120 68 m_proc->kill();
Chris@122 69 m_proc->deleteLater();
Chris@120 70 }
jtkorhonen@0 71 }
jtkorhonen@0 72
Chris@188 73 QString HgRunner::getUnbundledFileName()
Chris@188 74 {
Chris@240 75 return SettingsDialog::getUnbundledExtensionFileName();
Chris@188 76 }
Chris@188 77
Chris@180 78 QString HgRunner::unbundleExtension()
Chris@161 79 {
Chris@188 80 // Pull out the bundled Python file into a temporary file, and
Chris@188 81 // copy it to our known extension location, replacing the magic
Chris@188 82 // text NO_EASYHG_IMPORT_PATH with our installation location
Chris@188 83
Chris@161 84 QString bundled = ":easyhg.py";
Chris@188 85 QString unbundled = getUnbundledFileName();
Chris@188 86
Chris@188 87 QString target = QFileInfo(unbundled).path();
Chris@161 88 if (!QDir().mkpath(target)) {
Chris@161 89 DEBUG << "Failed to make unbundle path " << target << endl;
Chris@188 90 std::cerr << "Failed to make unbundle path " << target << std::endl;
Chris@180 91 return "";
Chris@161 92 }
Chris@188 93
Chris@161 94 QFile bf(bundled);
Chris@188 95 DEBUG << "unbundle: bundled file will be " << bundled << endl;
Chris@188 96 if (!bf.exists() || !bf.open(QIODevice::ReadOnly)) {
Chris@180 97 DEBUG << "Bundled extension is missing!" << endl;
Chris@180 98 return "";
Chris@180 99 }
Chris@188 100
Chris@188 101 QTemporaryFile tmpfile(QString("%1/easyhg.py.XXXXXX").arg(target));
Chris@188 102 tmpfile.setAutoRemove(false);
Chris@188 103 DEBUG << "unbundle: temp file will be " << tmpfile.fileName() << endl;
Chris@188 104 if (!tmpfile.open()) {
Chris@188 105 DEBUG << "Failed to open temporary file " << tmpfile.fileName() << endl;
Chris@188 106 std::cerr << "Failed to open temporary file " << tmpfile.fileName() << std::endl;
Chris@180 107 return "";
Chris@161 108 }
Chris@188 109
Chris@188 110 QString all = QString::fromUtf8(bf.readAll());
Chris@188 111 all.replace("NO_EASYHG_IMPORT_PATH", m_myDirPath);
Chris@188 112 tmpfile.write(all.toUtf8());
Chris@188 113 DEBUG << "unbundle: wrote " << all.length() << " characters" << endl;
Chris@188 114
Chris@188 115 tmpfile.close();
Chris@188 116
Chris@188 117 QFile ef(unbundled);
Chris@188 118 if (ef.exists()) {
Chris@188 119 DEBUG << "unbundle: removing old file " << unbundled << endl;
Chris@188 120 ef.remove();
Chris@188 121 }
Chris@188 122 DEBUG << "unbundle: renaming " << tmpfile.fileName() << " to " << unbundled << endl;
Chris@188 123 if (!tmpfile.rename(unbundled)) {
Chris@188 124 DEBUG << "Failed to move temporary file to target file " << unbundled << endl;
Chris@188 125 std::cerr << "Failed to move temporary file to target file " << unbundled << std::endl;
Chris@188 126 return "";
Chris@188 127 }
Chris@188 128
Chris@188 129 DEBUG << "Unbundled extension to " << unbundled << endl;
Chris@188 130 return unbundled;
Chris@161 131 }
Chris@161 132
Chris@109 133 void HgRunner::requestAction(HgAction action)
Chris@109 134 {
Chris@109 135 DEBUG << "requestAction " << action.action << endl;
Chris@109 136 bool pushIt = true;
Chris@109 137 if (m_queue.empty()) {
Chris@109 138 if (action == m_currentAction) {
Chris@109 139 // this request is identical to the thing we're executing
Chris@109 140 DEBUG << "requestAction: we're already handling this one, ignoring identical request" << endl;
Chris@109 141 pushIt = false;
Chris@109 142 }
Chris@109 143 } else {
Chris@109 144 HgAction last = m_queue.back();
Chris@109 145 if (action == last) {
Chris@109 146 // this request is identical to the previous thing we
Chris@109 147 // queued which we haven't executed yet
Chris@109 148 DEBUG << "requestAction: we're already queueing this one, ignoring identical request" << endl;
Chris@109 149 pushIt = false;
Chris@109 150 }
Chris@109 151 }
Chris@109 152 if (pushIt) m_queue.push_back(action);
Chris@109 153 checkQueue();
Chris@109 154 }
Chris@109 155
Chris@239 156 QString HgRunner::getHgBinaryName()
Chris@62 157 {
Chris@62 158 QSettings settings;
Chris@175 159 settings.beginGroup("Locations");
Chris@239 160 return settings.value("hgbinary", "").toString();
Chris@62 161 }
Chris@62 162
Chris@239 163 QString HgRunner::getExtensionLocation()
Chris@239 164 {
Chris@239 165 QSettings settings;
Chris@239 166 settings.beginGroup("Locations");
Chris@239 167 QString extpath = settings.value("extensionpath", "").toString();
Chris@239 168 if (extpath != "" && QFile(extpath).exists()) return extpath;
Chris@239 169 return "";
Chris@239 170 }
Chris@239 171
jtkorhonen@0 172 void HgRunner::started()
jtkorhonen@0 173 {
Chris@104 174 DEBUG << "started" << endl;
Chris@75 175 /*
Chris@104 176 m_proc->write("blah\n");
Chris@104 177 m_proc->write("blah\n");
Chris@104 178 m_proc -> closeWriteChannel();
Chris@75 179 */
jtkorhonen@0 180 }
jtkorhonen@0 181
Chris@84 182 void HgRunner::noteUsername(QString name)
Chris@75 183 {
Chris@84 184 m_userName = name;
Chris@75 185 }
Chris@75 186
Chris@84 187 void HgRunner::noteRealm(QString realm)
Chris@75 188 {
Chris@84 189 m_realm = realm;
Chris@84 190 }
Chris@84 191
Chris@84 192 void HgRunner::getUsername()
Chris@84 193 {
Chris@113 194 if (m_ptyFile) {
Chris@84 195 bool ok = false;
Chris@84 196 QString prompt = tr("User name:");
Chris@84 197 if (m_realm != "") {
Chris@84 198 prompt = tr("User name for \"%1\":").arg(m_realm);
Chris@84 199 }
Chris@84 200 QString pwd = QInputDialog::getText
Chris@84 201 (qobject_cast<QWidget *>(parent()),
Chris@84 202 tr("Enter user name"), prompt,
Chris@84 203 QLineEdit::Normal, QString(), &ok);
Chris@84 204 if (ok) {
Chris@113 205 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8());
Chris@113 206 m_ptyFile->flush();
Chris@84 207 return;
Chris@111 208 } else {
Chris@111 209 DEBUG << "HgRunner::getUsername: user cancelled" << endl;
Chris@111 210 killCurrentCommand();
Chris@111 211 return;
Chris@84 212 }
Chris@84 213 }
Chris@84 214 // user cancelled or something went wrong
Chris@111 215 DEBUG << "HgRunner::getUsername: something went wrong" << endl;
Chris@84 216 killCurrentCommand();
Chris@84 217 }
Chris@84 218
Chris@84 219 void HgRunner::getPassword()
Chris@84 220 {
Chris@113 221 if (m_ptyFile) {
Chris@84 222 bool ok = false;
Chris@84 223 QString prompt = tr("Password:");
Chris@84 224 if (m_userName != "") {
Chris@84 225 if (m_realm != "") {
Chris@84 226 prompt = tr("Password for \"%1\" at \"%2\":")
Chris@84 227 .arg(m_userName).arg(m_realm);
Chris@75 228 } else {
Chris@84 229 prompt = tr("Password for user \"%1\":")
Chris@84 230 .arg(m_userName);
Chris@75 231 }
Chris@75 232 }
Chris@84 233 QString pwd = QInputDialog::getText
Chris@84 234 (qobject_cast<QWidget *>(parent()),
Chris@84 235 tr("Enter password"), prompt,
Chris@84 236 QLineEdit::Password, QString(), &ok);
Chris@84 237 if (ok) {
Chris@113 238 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8());
Chris@113 239 m_ptyFile->flush();
Chris@84 240 return;
Chris@111 241 } else {
Chris@111 242 DEBUG << "HgRunner::getPassword: user cancelled" << endl;
Chris@111 243 killCurrentCommand();
Chris@111 244 return;
Chris@84 245 }
Chris@75 246 }
Chris@84 247 // user cancelled or something went wrong
Chris@111 248 DEBUG << "HgRunner::getPassword: something went wrong" << endl;
Chris@84 249 killCurrentCommand();
Chris@84 250 }
Chris@84 251
Chris@113 252 bool HgRunner::checkPrompts(QString chunk)
Chris@84 253 {
Chris@93 254 //DEBUG << "checkPrompts: " << chunk << endl;
Chris@84 255
Chris@128 256 if (!m_currentAction.mayBeInteractive()) return false;
Chris@128 257
Chris@84 258 QString text = chunk.trimmed();
Chris@84 259 QString lower = text.toLower();
Chris@84 260 if (lower.endsWith("password:")) {
Chris@84 261 getPassword();
Chris@113 262 return true;
Chris@84 263 }
Chris@128 264 if (lower.endsWith("user:") || lower.endsWith("username:")) {
Chris@84 265 getUsername();
Chris@113 266 return true;
Chris@84 267 }
Chris@128 268 QRegExp userRe("\\buser(name)?:\\s*([^\\s]+)");
Chris@84 269 if (userRe.indexIn(text) >= 0) {
Chris@128 270 noteUsername(userRe.cap(2));
Chris@84 271 }
Chris@84 272 QRegExp realmRe("\\brealmr:\\s*([^\\s]+)");
Chris@84 273 if (realmRe.indexIn(text) >= 0) {
Chris@84 274 noteRealm(realmRe.cap(1));
Chris@84 275 }
Chris@113 276 return false;
Chris@84 277 }
Chris@84 278
Chris@110 279 void HgRunner::dataReadyStdout()
Chris@84 280 {
Chris@110 281 DEBUG << "dataReadyStdout" << endl;
Chris@110 282 QString chunk = QString::fromUtf8(m_proc->readAllStandardOutput());
Chris@113 283 if (!checkPrompts(chunk)) {
Chris@113 284 m_stdout += chunk;
Chris@113 285 }
Chris@110 286 }
Chris@110 287
Chris@110 288 void HgRunner::dataReadyStderr()
Chris@110 289 {
Chris@110 290 DEBUG << "dataReadyStderr" << endl;
Chris@110 291 QString chunk = QString::fromUtf8(m_proc->readAllStandardError());
Chris@113 292 DEBUG << chunk;
Chris@113 293 if (!checkPrompts(chunk)) {
Chris@113 294 m_stderr += chunk;
Chris@113 295 }
Chris@113 296 }
Chris@113 297
Chris@113 298 void HgRunner::dataReadyPty()
Chris@113 299 {
Chris@113 300 DEBUG << "dataReadyPty" << endl;
Chris@113 301 QString chunk = QString::fromUtf8(m_ptyFile->readAll());
Chris@113 302 DEBUG << "chunk of " << chunk.length() << " chars" << endl;
Chris@113 303 if (!checkPrompts(chunk)) {
Chris@113 304 m_stdout += chunk;
Chris@113 305 }
Chris@75 306 }
Chris@75 307
Chris@189 308 void HgRunner::error(QProcess::ProcessError)
Chris@189 309 {
Chris@189 310 finished(-1, QProcess::CrashExit);
Chris@189 311 }
Chris@189 312
jtkorhonen@0 313 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
jtkorhonen@0 314 {
Chris@109 315 // Save the current action and reset m_currentAction before we
Chris@109 316 // emit a signal to mark the completion; otherwise we may be
Chris@109 317 // resetting the action after a slot has already tried to set it
Chris@109 318 // to something else to start a new action
Chris@109 319
Chris@109 320 HgAction completedAction = m_currentAction;
Chris@109 321
Chris@84 322 m_isRunning = false;
Chris@109 323 m_currentAction = HgAction();
Chris@84 324
Chris@195 325 //closeProcInput();
Chris@189 326 m_proc->deleteLater();
Chris@113 327 m_proc = 0;
jtkorhonen@0 328
Chris@109 329 if (completedAction.action == ACT_NONE) {
Chris@109 330 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl;
Chris@62 331 } else {
Chris@113 332 if (procExitCode == 0 && procExitStatus == QProcess::NormalExit) {
Chris@113 333 DEBUG << "HgRunner::finished: Command completed successfully"
Chris@113 334 << endl;
Chris@124 335 // DEBUG << "stdout is " << m_stdout << endl;
Chris@113 336 emit commandCompleted(completedAction, m_stdout);
Chris@113 337 } else {
Chris@113 338 DEBUG << "HgRunner::finished: Command failed, exit code "
Chris@113 339 << procExitCode << ", exit status " << procExitStatus
Chris@113 340 << ", stderr follows" << endl;
Chris@113 341 DEBUG << m_stderr << endl;
Chris@113 342 emit commandFailed(completedAction, m_stderr);
Chris@113 343 }
jtkorhonen@0 344 }
Chris@109 345
Chris@109 346 checkQueue();
jtkorhonen@0 347 }
jtkorhonen@0 348
Chris@182 349 void HgRunner::killCurrentActions()
Chris@182 350 {
Chris@182 351 m_queue.clear();
Chris@182 352 killCurrentCommand();
Chris@182 353 }
Chris@182 354
Chris@62 355 void HgRunner::killCurrentCommand()
jtkorhonen@0 356 {
Chris@109 357 if (m_isRunning) {
Chris@113 358 m_currentAction.action = ACT_NONE; // so that we don't bother to notify
Chris@113 359 m_proc->kill();
jtkorhonen@0 360 }
jtkorhonen@0 361 }
jtkorhonen@0 362
Chris@109 363 void HgRunner::checkQueue()
Chris@62 364 {
Chris@109 365 if (m_isRunning) {
Chris@109 366 return;
Chris@109 367 }
Chris@109 368 if (m_queue.empty()) {
Chris@109 369 hide();
Chris@109 370 return;
Chris@109 371 }
Chris@109 372 HgAction toRun = m_queue.front();
Chris@109 373 m_queue.pop_front();
Chris@109 374 DEBUG << "checkQueue: have action: running " << toRun.action << endl;
Chris@109 375 startCommand(toRun);
Chris@109 376 }
Chris@109 377
Chris@109 378 void HgRunner::startCommand(HgAction action)
Chris@109 379 {
Chris@109 380 QString executable = action.executable;
Chris@109 381 bool interactive = false;
Chris@109 382 QStringList params = action.params;
Chris@109 383
Chris@257 384 QSettings settings;
Chris@257 385 settings.beginGroup("General");
Chris@257 386
Chris@109 387 if (executable == "") {
Chris@109 388 // This is a Hg command
Chris@239 389 executable = getHgBinaryName();
Chris@161 390
Chris@161 391 if (action.mayBeInteractive()) {
Chris@161 392 params.push_front("ui.interactive=true");
Chris@161 393 params.push_front("--config");
Chris@176 394
Chris@176 395 if (settings.value("useextension", true).toBool()) {
Chris@239 396 QString extpath = getExtensionLocation();
Chris@180 397 params.push_front(QString("extensions.easyhg=%1").arg(extpath));
Chris@176 398 params.push_front("--config");
Chris@176 399 }
Chris@161 400 interactive = true;
Chris@161 401 }
Chris@161 402
Chris@161 403 //!!! want an option to use the mercurial_keyring extension as well
Chris@107 404 }
jtkorhonen@0 405
Chris@84 406 m_isRunning = true;
jtkorhonen@0 407 setRange(0, 0);
Chris@115 408 if (!action.shouldBeFast()) show();
Chris@110 409 m_stdout.clear();
Chris@110 410 m_stderr.clear();
Chris@84 411 m_realm = "";
Chris@84 412 m_userName = "";
jtkorhonen@0 413
Chris@113 414 m_proc = new QProcess;
Chris@113 415
Chris@177 416 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
Chris@177 417
Chris@177 418 #ifdef Q_OS_WIN32
Chris@257 419 // On Win32 we like to bundle Hg and other executables with EasyHg
Chris@177 420 if (m_myDirPath != "") {
Chris@177 421 env.insert("PATH", m_myDirPath + ";" + env.value("PATH"));
Chris@172 422 }
Chris@172 423 #endif
Chris@172 424
Chris@257 425 #ifdef Q_OS_MAC
Chris@257 426 // On OS/X 10.6, Python is 64-bit by default but our Hg extension
Chris@257 427 // is only available in 32-bit
Chris@257 428 if (settings.value("python32", true).toBool()) {
Chris@261 429 env.insert("VERSIONER_PYTHON_PREFER_32_BIT", "1");
Chris@257 430 }
Chris@257 431 #endif
Chris@257 432
Chris@113 433 env.insert("LANG", "en_US.utf8");
Chris@113 434 env.insert("LC_ALL", "en_US.utf8");
Chris@113 435 env.insert("HGPLAIN", "1");
Chris@113 436 m_proc->setProcessEnvironment(env);
Chris@113 437
Chris@113 438 connect(m_proc, SIGNAL(started()), this, SLOT(started()));
Chris@189 439 connect(m_proc, SIGNAL(error(QProcess::ProcessError)),
Chris@189 440 this, SLOT(error(QProcess::ProcessError)));
Chris@113 441 connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)),
Chris@113 442 this, SLOT(finished(int, QProcess::ExitStatus)));
Chris@113 443 connect(m_proc, SIGNAL(readyReadStandardOutput()),
Chris@113 444 this, SLOT(dataReadyStdout()));
Chris@113 445 connect(m_proc, SIGNAL(readyReadStandardError()),
Chris@113 446 this, SLOT(dataReadyStderr()));
Chris@113 447
Chris@109 448 if (!action.workingDir.isEmpty()) {
Chris@109 449 m_proc->setWorkingDirectory(action.workingDir);
jtkorhonen@0 450 }
jtkorhonen@0 451
Chris@107 452 if (interactive) {
Chris@111 453 openTerminal();
Chris@111 454 if (m_ptySlaveFilename != "") {
Chris@113 455 DEBUG << "HgRunner: connecting to pseudoterminal" << endl;
Chris@107 456 m_proc->setStandardInputFile(m_ptySlaveFilename);
Chris@114 457 // m_proc->setStandardOutputFile(m_ptySlaveFilename);
Chris@113 458 // m_proc->setStandardErrorFile(m_ptySlaveFilename);
Chris@107 459 }
Chris@84 460 }
Chris@84 461
Chris@109 462 QString cmdline = executable;
Chris@57 463 foreach (QString param, params) cmdline += " " + param;
Chris@64 464 DEBUG << "HgRunner: starting: " << cmdline << " with cwd "
Chris@109 465 << action.workingDir << endl;
Chris@43 466
Chris@109 467 m_currentAction = action;
Chris@109 468
Chris@113 469 // fill these out with what we actually ran
Chris@113 470 m_currentAction.executable = executable;
Chris@113 471 m_currentAction.params = params;
Chris@113 472
Chris@109 473 DEBUG << "set current action to " << m_currentAction.action << endl;
Chris@109 474
Chris@238 475 emit commandStarting(action);
Chris@238 476
Chris@109 477 m_proc->start(executable, params);
Chris@84 478 }
Chris@84 479
Chris@84 480 void HgRunner::closeProcInput()
Chris@84 481 {
Chris@84 482 DEBUG << "closeProcInput" << endl;
Chris@84 483
Chris@84 484 m_proc->closeWriteChannel();
Chris@111 485 }
Chris@111 486
Chris@111 487 void HgRunner::openTerminal()
Chris@111 488 {
Chris@111 489 #ifndef Q_OS_WIN32
Chris@111 490 if (m_ptySlaveFilename != "") return; // already open
Chris@111 491 DEBUG << "HgRunner::openTerminal: trying to open new pty" << endl;
Chris@111 492 int master = posix_openpt(O_RDWR | O_NOCTTY);
Chris@111 493 if (master < 0) {
Chris@111 494 DEBUG << "openpt failed" << endl;
Chris@111 495 perror("openpt failed");
Chris@111 496 return;
Chris@111 497 }
Chris@113 498 struct termios t;
Chris@113 499 if (tcgetattr(master, &t)) {
Chris@113 500 DEBUG << "tcgetattr failed" << endl;
Chris@113 501 perror("tcgetattr failed");
Chris@113 502 }
Chris@113 503 cfmakeraw(&t);
Chris@113 504 if (tcsetattr(master, TCSANOW, &t)) {
Chris@113 505 DEBUG << "tcsetattr failed" << endl;
Chris@113 506 perror("tcsetattr failed");
Chris@113 507 }
Chris@111 508 if (grantpt(master)) {
Chris@111 509 perror("grantpt failed");
Chris@111 510 }
Chris@111 511 if (unlockpt(master)) {
Chris@111 512 perror("unlockpt failed");
Chris@111 513 }
Chris@111 514 char *slave = ptsname(master);
Chris@111 515 if (!slave) {
Chris@111 516 perror("ptsname failed");
Chris@111 517 ::close(master);
Chris@111 518 return;
Chris@111 519 }
Chris@111 520 m_ptyMasterFd = master;
Chris@113 521 m_ptyFile = new QFile();
Chris@113 522 connect(m_ptyFile, SIGNAL(readyRead()), this, SLOT(dataReadyPty()));
Chris@113 523 if (!m_ptyFile->open(m_ptyMasterFd, QFile::ReadWrite)) {
Chris@113 524 DEBUG << "HgRunner::openTerminal: Failed to open QFile on master fd" << endl;
Chris@113 525 }
Chris@111 526 m_ptySlaveFilename = slave;
Chris@111 527 DEBUG << "HgRunner::openTerminal: succeeded, slave is "
Chris@111 528 << m_ptySlaveFilename << endl;
Chris@111 529 #endif
Chris@111 530 }
Chris@111 531
Chris@111 532 void HgRunner::closeTerminal()
Chris@111 533 {
Chris@84 534 #ifndef Q_OS_WIN32
Chris@84 535 if (m_ptySlaveFilename != "") {
Chris@113 536 delete m_ptyFile;
Chris@113 537 m_ptyFile = 0;
Chris@84 538 ::close(m_ptyMasterFd);
Chris@84 539 m_ptySlaveFilename = "";
Chris@84 540 }
Chris@84 541 #endif
jtkorhonen@0 542 }