annotate incomingdialog.cpp @ 143:f61f032b06f9

* Fix another use of stderr as identifier
author Chris Cannam
date Wed, 01 Dec 2010 11:54:01 +0000
parents 63c2f3f61c79
children 8fd71f570884
rev   line source
Chris@125 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@125 2
Chris@125 3 /*
Chris@125 4 EasyMercurial
Chris@125 5
Chris@125 6 Based on hgExplorer by Jari Korhonen
Chris@125 7 Copyright (c) 2010 Jari Korhonen
Chris@125 8 Copyright (c) 2010 Chris Cannam
Chris@125 9 Copyright (c) 2010 Queen Mary, University of London
Chris@125 10
Chris@125 11 This program is free software; you can redistribute it and/or
Chris@125 12 modify it under the terms of the GNU General Public License as
Chris@125 13 published by the Free Software Foundation; either version 2 of the
Chris@125 14 License, or (at your option) any later version. See the file
Chris@125 15 COPYING included with this distribution for more information.
Chris@125 16 */
Chris@125 17
Chris@125 18 #include "incomingdialog.h"
Chris@125 19 #include "changeset.h"
Chris@125 20 #include "common.h"
Chris@125 21
Chris@125 22 #include <QScrollArea>
Chris@125 23 #include <QApplication>
Chris@125 24 #include <QDialogButtonBox>
Chris@125 25 #include <QLabel>
Chris@125 26 #include <QGridLayout>
Chris@125 27 #include <QStyle>
Chris@125 28
Chris@125 29 IncomingDialog::IncomingDialog(QWidget *w, QString text) :
Chris@125 30 QDialog(w)
Chris@125 31 {
Chris@125 32 QString head;
Chris@125 33 QString body;
Chris@125 34 bool scroll;
Chris@125 35
Chris@125 36 Changesets csets = Changeset::parseChangesets(text);
Chris@125 37 if (csets.empty()) {
Chris@125 38 head = tr("No changes waiting to pull");
Chris@125 39 if (text.trimmed() != "") {
Chris@125 40 body = QString("<p>%1</p><code>%2</code>")
Chris@125 41 .arg(tr("The command output was:"))
Chris@125 42 .arg(xmlEncode(text).replace("\n", "<br>"));
Chris@125 43 }
Chris@125 44 scroll = false;
Chris@125 45 } else {
Chris@125 46 head = tr("There are %n change(s) ready to pull", "", csets.size());
Chris@125 47 foreach (Changeset *cs, csets) {
Chris@125 48 body += cs->formatHtml() + "<p>";
Chris@125 49 delete cs;
Chris@125 50 }
Chris@125 51 scroll = true;
Chris@125 52 }
Chris@125 53
Chris@125 54 QGridLayout *layout = new QGridLayout;
Chris@125 55 setLayout(layout);
Chris@125 56
Chris@125 57 QLabel *info = new QLabel;
Chris@125 58 QStyle *style = qApp->style();
Chris@125 59 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
Chris@125 60 info->setPixmap(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this)
Chris@125 61 .pixmap(iconSize, iconSize));
Chris@125 62 layout->addWidget(info, 0, 0);
Chris@125 63
Chris@125 64 QLabel *headLabel = new QLabel(QString("<qt><h3>%1</h3></qt>").arg(head));
Chris@125 65 layout->addWidget(headLabel, 0, 1);
Chris@125 66
Chris@125 67 QLabel *textLabel = new QLabel(body);
Chris@125 68
Chris@125 69 if (scroll) {
Chris@125 70 QScrollArea *sa = new QScrollArea;
Chris@125 71 layout->addWidget(sa, 1, 1);
Chris@125 72 layout->setRowStretch(1, 20);
Chris@125 73 sa->setWidget(textLabel);
Chris@125 74 } else {
Chris@125 75 layout->addWidget(textLabel, 1, 1);
Chris@125 76 }
Chris@125 77
Chris@125 78 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
Chris@125 79 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@125 80 layout->addWidget(bb, 2, 0, 1, 2);
Chris@125 81 }
Chris@125 82
Chris@125 83