comparison src/workstatuswidget.cpp @ 370:b9c153e00e84

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