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@560
|
8 Copyright (c) 2012 Chris Cannam
|
Chris@560
|
9 Copyright (c) 2012 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@523
|
21 #include "squeezedlabel.h"
|
Chris@283
|
22
|
Chris@283
|
23 #include <QGridLayout>
|
Chris@283
|
24 #include <QSpacerItem>
|
Chris@283
|
25 #include <QLabel>
|
Chris@283
|
26 #include <QProcess>
|
Chris@283
|
27 #include <QDir>
|
Chris@283
|
28
|
Chris@283
|
29 WorkStatusWidget::WorkStatusWidget(QWidget *parent) :
|
Chris@283
|
30 QWidget(parent)
|
Chris@283
|
31 {
|
Chris@283
|
32 QGridLayout *layout = new QGridLayout;
|
Chris@297
|
33 layout->setMargin(6);
|
Chris@297
|
34 layout->setSpacing(6);
|
Chris@283
|
35 setLayout(layout);
|
Chris@283
|
36
|
Chris@283
|
37 int row = 0;
|
Chris@283
|
38
|
Chris@283
|
39 #ifndef Q_OS_MAC
|
Chris@283
|
40 layout->addItem(new QSpacerItem(1, 1), row, 0);
|
Chris@283
|
41 ++row;
|
Chris@283
|
42 #endif
|
Chris@283
|
43
|
Chris@297
|
44 layout->addWidget(new QLabel(tr("Local:")), row, 1);
|
Chris@283
|
45
|
Chris@283
|
46 m_openButton = new ClickableLabel;
|
Chris@283
|
47 QFont f(m_openButton->font());
|
Chris@283
|
48 f.setBold(true);
|
Chris@283
|
49 m_openButton->setFont(f);
|
Chris@283
|
50 m_openButton->setMouseUnderline(true);
|
Chris@283
|
51 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
|
Chris@523
|
52 layout->addWidget(m_openButton, row, 2, 1, 2);
|
Chris@283
|
53
|
Chris@283
|
54 ++row;
|
Chris@297
|
55 layout->addWidget(new QLabel(tr("Remote:")), row, 1);
|
Chris@523
|
56 m_remoteURLLabel = new SqueezedLabel;
|
Chris@375
|
57 m_remoteURLLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
Chris@297
|
58 layout->addWidget(m_remoteURLLabel, row, 2, 1, 2);
|
Chris@283
|
59
|
Chris@283
|
60 ++row;
|
Chris@297
|
61 layout->addWidget(new QLabel(tr("State:")), row, 1);
|
Chris@283
|
62 m_stateLabel = new QLabel;
|
Chris@297
|
63 layout->addWidget(m_stateLabel, row, 2, 1, 2);
|
Chris@283
|
64
|
Chris@297
|
65 layout->setColumnStretch(2, 20);
|
Chris@283
|
66
|
Chris@283
|
67
|
Chris@283
|
68 }
|
Chris@283
|
69
|
Chris@283
|
70 WorkStatusWidget::~WorkStatusWidget()
|
Chris@283
|
71 {
|
Chris@283
|
72 }
|
Chris@283
|
73
|
Chris@283
|
74 void
|
Chris@283
|
75 WorkStatusWidget::setLocalPath(QString p)
|
Chris@283
|
76 {
|
Chris@283
|
77 m_localPath = p;
|
Chris@283
|
78 m_openButton->setText(p);
|
Chris@283
|
79 m_openButton->setEnabled(QDir(m_localPath).exists());
|
Chris@283
|
80 }
|
Chris@283
|
81
|
Chris@283
|
82 void
|
Chris@283
|
83 WorkStatusWidget::setRemoteURL(QString r)
|
Chris@283
|
84 {
|
Chris@283
|
85 m_remoteURL = r;
|
Chris@283
|
86 m_remoteURLLabel->setText(r);
|
Chris@283
|
87 }
|
Chris@283
|
88
|
Chris@283
|
89 void
|
Chris@283
|
90 WorkStatusWidget::setState(QString b)
|
Chris@283
|
91 {
|
Chris@283
|
92 m_state = b;
|
Chris@283
|
93 updateStateLabel();
|
Chris@283
|
94 }
|
Chris@283
|
95
|
Chris@283
|
96 void
|
Chris@283
|
97 WorkStatusWidget::updateStateLabel()
|
Chris@283
|
98 {
|
Chris@283
|
99 m_stateLabel->setText(m_state);
|
Chris@283
|
100 }
|
Chris@283
|
101
|
Chris@283
|
102 void
|
Chris@283
|
103 WorkStatusWidget::openButtonClicked()
|
Chris@283
|
104 {
|
Chris@283
|
105 QDir d(m_localPath);
|
Chris@283
|
106 if (d.exists()) {
|
Chris@283
|
107 QStringList args;
|
Chris@283
|
108 QString path = d.canonicalPath();
|
Chris@283
|
109 #if defined Q_OS_WIN32
|
Chris@283
|
110 // Although the Win32 API is quite happy to have
|
Chris@283
|
111 // forward slashes as directory separators, Windows
|
Chris@283
|
112 // Explorer is not
|
Chris@283
|
113 path = path.replace('/', '\\');
|
Chris@283
|
114 args << path;
|
Chris@283
|
115 QProcess::execute("c:/windows/explorer.exe", args);
|
Chris@283
|
116 #else
|
Chris@283
|
117 args << path;
|
Chris@283
|
118 QProcess::execute(
|
Chris@283
|
119 #if defined Q_OS_MAC
|
Chris@283
|
120 "/usr/bin/open",
|
Chris@283
|
121 #else
|
Chris@283
|
122 "/usr/bin/xdg-open",
|
Chris@283
|
123 #endif
|
Chris@283
|
124 args);
|
Chris@283
|
125 #endif
|
Chris@283
|
126 }
|
Chris@283
|
127 }
|