Chris@283
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@283
|
2
|
Chris@283
|
3 /*
|
Chris@283
|
4 EasyMercurial
|
Chris@283
|
5
|
Chris@283
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@283
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@283
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@283
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@283
|
10
|
Chris@283
|
11 This program is free software; you can redistribute it and/or
|
Chris@283
|
12 modify it under the terms of the GNU General Public License as
|
Chris@283
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@283
|
14 License, or (at your option) any later version. See the file
|
Chris@283
|
15 COPYING included with this distribution for more information.
|
Chris@283
|
16 */
|
Chris@283
|
17
|
Chris@283
|
18 #include "workstatuswidget.h"
|
Chris@283
|
19 #include "debug.h"
|
Chris@283
|
20 #include "clickablelabel.h"
|
Chris@283
|
21
|
Chris@283
|
22 #include <QGridLayout>
|
Chris@283
|
23 #include <QSpacerItem>
|
Chris@283
|
24 #include <QLabel>
|
Chris@283
|
25 #include <QProcess>
|
Chris@283
|
26 #include <QDir>
|
Chris@283
|
27
|
Chris@283
|
28 WorkStatusWidget::WorkStatusWidget(QWidget *parent) :
|
Chris@283
|
29 QWidget(parent)
|
Chris@283
|
30 {
|
Chris@283
|
31 QGridLayout *layout = new QGridLayout;
|
Chris@283
|
32 layout->setMargin(10);
|
Chris@283
|
33 setLayout(layout);
|
Chris@283
|
34
|
Chris@283
|
35 int row = 0;
|
Chris@283
|
36
|
Chris@283
|
37 #ifndef Q_OS_MAC
|
Chris@283
|
38 layout->addItem(new QSpacerItem(1, 1), row, 0);
|
Chris@283
|
39 ++row;
|
Chris@283
|
40 #endif
|
Chris@283
|
41
|
Chris@283
|
42 layout->addWidget(new QLabel(tr("Local:")), row, 0);
|
Chris@283
|
43
|
Chris@283
|
44 m_openButton = new ClickableLabel;
|
Chris@283
|
45 QFont f(m_openButton->font());
|
Chris@283
|
46 f.setBold(true);
|
Chris@283
|
47 m_openButton->setFont(f);
|
Chris@283
|
48 m_openButton->setMouseUnderline(true);
|
Chris@283
|
49 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
|
Chris@283
|
50 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft);
|
Chris@283
|
51
|
Chris@283
|
52 ++row;
|
Chris@283
|
53 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
|
Chris@283
|
54 m_remoteURLLabel = new QLabel;
|
Chris@283
|
55 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
|
Chris@283
|
56
|
Chris@283
|
57 ++row;
|
Chris@283
|
58 layout->addWidget(new QLabel(tr("State:")), row, 0);
|
Chris@283
|
59 m_stateLabel = new QLabel;
|
Chris@283
|
60 layout->addWidget(m_stateLabel, row, 1, 1, 2);
|
Chris@283
|
61
|
Chris@283
|
62 layout->setColumnStretch(1, 20);
|
Chris@283
|
63
|
Chris@283
|
64
|
Chris@283
|
65 }
|
Chris@283
|
66
|
Chris@283
|
67 WorkStatusWidget::~WorkStatusWidget()
|
Chris@283
|
68 {
|
Chris@283
|
69 }
|
Chris@283
|
70
|
Chris@283
|
71 void
|
Chris@283
|
72 WorkStatusWidget::setLocalPath(QString p)
|
Chris@283
|
73 {
|
Chris@283
|
74 m_localPath = p;
|
Chris@283
|
75 m_openButton->setText(p);
|
Chris@283
|
76 m_openButton->setEnabled(QDir(m_localPath).exists());
|
Chris@283
|
77 }
|
Chris@283
|
78
|
Chris@283
|
79 void
|
Chris@283
|
80 WorkStatusWidget::setRemoteURL(QString r)
|
Chris@283
|
81 {
|
Chris@283
|
82 m_remoteURL = r;
|
Chris@283
|
83 m_remoteURLLabel->setText(r);
|
Chris@283
|
84 }
|
Chris@283
|
85
|
Chris@283
|
86 void
|
Chris@283
|
87 WorkStatusWidget::setState(QString b)
|
Chris@283
|
88 {
|
Chris@283
|
89 m_state = b;
|
Chris@283
|
90 updateStateLabel();
|
Chris@283
|
91 }
|
Chris@283
|
92
|
Chris@283
|
93 void
|
Chris@283
|
94 WorkStatusWidget::updateStateLabel()
|
Chris@283
|
95 {
|
Chris@283
|
96 m_stateLabel->setText(m_state);
|
Chris@283
|
97 }
|
Chris@283
|
98
|
Chris@283
|
99 void
|
Chris@283
|
100 WorkStatusWidget::openButtonClicked()
|
Chris@283
|
101 {
|
Chris@283
|
102 QDir d(m_localPath);
|
Chris@283
|
103 if (d.exists()) {
|
Chris@283
|
104 QStringList args;
|
Chris@283
|
105 QString path = d.canonicalPath();
|
Chris@283
|
106 #if defined Q_OS_WIN32
|
Chris@283
|
107 // Although the Win32 API is quite happy to have
|
Chris@283
|
108 // forward slashes as directory separators, Windows
|
Chris@283
|
109 // Explorer is not
|
Chris@283
|
110 path = path.replace('/', '\\');
|
Chris@283
|
111 args << path;
|
Chris@283
|
112 QProcess::execute("c:/windows/explorer.exe", args);
|
Chris@283
|
113 #else
|
Chris@283
|
114 args << path;
|
Chris@283
|
115 QProcess::execute(
|
Chris@283
|
116 #if defined Q_OS_MAC
|
Chris@283
|
117 "/usr/bin/open",
|
Chris@283
|
118 #else
|
Chris@283
|
119 "/usr/bin/xdg-open",
|
Chris@283
|
120 #endif
|
Chris@283
|
121 args);
|
Chris@283
|
122 #endif
|
Chris@283
|
123 }
|
Chris@283
|
124 }
|