1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "pendingchangesdialog.h"
27 
28 #include <QRegularExpression>
29 
30 
31 using namespace Perforce::Internal;
32 
PendingChangesDialog(const QString & data,QWidget * parent)33 PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent) : QDialog(parent)
34 {
35     m_ui.setupUi(this);
36     if (!data.isEmpty()) {
37         const QRegularExpression r(QLatin1String("Change\\s(\\d+?).*?\\s\\*?pending\\*?\\s(.+?)\n"));
38         QListWidgetItem *item;
39         QRegularExpressionMatchIterator it = r.globalMatch(data);
40         while (it.hasNext()) {
41             const QRegularExpressionMatch match = it.next();
42             item = new QListWidgetItem(tr("Change %1: %2").arg(match.captured(1),
43                                                                match.captured(2).trimmed()),
44                                        m_ui.listWidget);
45             item->setData(234, match.captured(1).trimmed());
46         }
47     }
48     m_ui.listWidget->setSelectionMode(QListWidget::SingleSelection);
49     if (m_ui.listWidget->count()) {
50         m_ui.listWidget->setCurrentRow(0);
51         m_ui.submitButton->setEnabled(true);
52     } else {
53         m_ui.submitButton->setEnabled(false);
54     }
55 }
56 
changeNumber() const57 int PendingChangesDialog::changeNumber() const
58 {
59     QListWidgetItem *item = m_ui.listWidget->item(m_ui.listWidget->currentRow());
60     if (!item)
61         return -1;
62     bool ok = true;
63     int i = item->data(234).toInt(&ok);
64     return ok ? i : -1;
65 }
66