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@644
|
8 Copyright (c) 2013 Chris Cannam
|
Chris@644
|
9 Copyright (c) 2013 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@298
|
43 } else {
|
Chris@298
|
44 body = tr("<qt>Your local repository already contains all changes found in the remote repository.</qt>");
|
Chris@298
|
45 }
|
Chris@125
|
46 scroll = false;
|
Chris@125
|
47 } else {
|
Chris@125
|
48 head = tr("There are %n change(s) ready to pull", "", csets.size());
|
Chris@125
|
49 foreach (Changeset *cs, csets) {
|
Chris@125
|
50 body += cs->formatHtml() + "<p>";
|
Chris@125
|
51 delete cs;
|
Chris@125
|
52 }
|
Chris@125
|
53 scroll = true;
|
Chris@125
|
54 }
|
Chris@125
|
55
|
Chris@125
|
56 QGridLayout *layout = new QGridLayout;
|
Chris@125
|
57 setLayout(layout);
|
Chris@125
|
58
|
Chris@125
|
59 QLabel *info = new QLabel;
|
Chris@125
|
60 QStyle *style = qApp->style();
|
Chris@125
|
61 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
|
Chris@125
|
62 info->setPixmap(style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this)
|
Chris@125
|
63 .pixmap(iconSize, iconSize));
|
Chris@298
|
64 layout->addWidget(info, 0, 0, 2, 1);
|
Chris@125
|
65
|
Chris@125
|
66 QLabel *headLabel = new QLabel(QString("<qt><h3>%1</h3></qt>").arg(head));
|
Chris@125
|
67 layout->addWidget(headLabel, 0, 1);
|
Chris@125
|
68
|
Chris@125
|
69 QLabel *textLabel = new QLabel(body);
|
Chris@298
|
70 if (csets.empty()) textLabel->setWordWrap(true);
|
Chris@125
|
71
|
Chris@125
|
72 if (scroll) {
|
Chris@125
|
73 QScrollArea *sa = new QScrollArea;
|
Chris@125
|
74 layout->addWidget(sa, 1, 1);
|
Chris@125
|
75 layout->setRowStretch(1, 20);
|
Chris@125
|
76 sa->setWidget(textLabel);
|
Chris@125
|
77 } else {
|
Chris@125
|
78 layout->addWidget(textLabel, 1, 1);
|
Chris@125
|
79 }
|
Chris@125
|
80
|
Chris@125
|
81 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
|
Chris@125
|
82 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
|
Chris@125
|
83 layout->addWidget(bb, 2, 0, 1, 2);
|
Chris@300
|
84
|
Chris@300
|
85 layout->setColumnStretch(1, 20);
|
Chris@300
|
86 setMinimumWidth(400);
|
Chris@125
|
87 }
|
Chris@125
|
88
|
Chris@125
|
89
|