comparison workstatuswidget.cpp @ 283:bc39f2e28da8 status_outside_tabs

Separate out work-status code from the file status widget
author Chris Cannam
date Mon, 21 Feb 2011 08:48:31 +0000
parents
children e4284fab6962
comparison
equal deleted inserted replaced
282:1ec306df738e 283:bc39f2e28da8
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(10);
33 setLayout(layout);
34
35 int row = 0;
36
37 #ifndef Q_OS_MAC
38 layout->addItem(new QSpacerItem(1, 1), row, 0);
39 ++row;
40 #endif
41
42 layout->addWidget(new QLabel(tr("Local:")), row, 0);
43
44 m_openButton = new ClickableLabel;
45 QFont f(m_openButton->font());
46 f.setBold(true);
47 m_openButton->setFont(f);
48 m_openButton->setMouseUnderline(true);
49 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
50 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft);
51
52 ++row;
53 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
54 m_remoteURLLabel = new QLabel;
55 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
56
57 ++row;
58 layout->addWidget(new QLabel(tr("State:")), row, 0);
59 m_stateLabel = new QLabel;
60 layout->addWidget(m_stateLabel, row, 1, 1, 2);
61
62 layout->setColumnStretch(1, 20);
63
64
65 }
66
67 WorkStatusWidget::~WorkStatusWidget()
68 {
69 }
70
71 void
72 WorkStatusWidget::setLocalPath(QString p)
73 {
74 m_localPath = p;
75 m_openButton->setText(p);
76 m_openButton->setEnabled(QDir(m_localPath).exists());
77 }
78
79 void
80 WorkStatusWidget::setRemoteURL(QString r)
81 {
82 m_remoteURL = r;
83 m_remoteURLLabel->setText(r);
84 }
85
86 void
87 WorkStatusWidget::setState(QString b)
88 {
89 m_state = b;
90 updateStateLabel();
91 }
92
93 void
94 WorkStatusWidget::updateStateLabel()
95 {
96 m_stateLabel->setText(m_state);
97 }
98
99 void
100 WorkStatusWidget::openButtonClicked()
101 {
102 QDir d(m_localPath);
103 if (d.exists()) {
104 QStringList args;
105 QString path = d.canonicalPath();
106 #if defined Q_OS_WIN32
107 // Although the Win32 API is quite happy to have
108 // forward slashes as directory separators, Windows
109 // Explorer is not
110 path = path.replace('/', '\\');
111 args << path;
112 QProcess::execute("c:/windows/explorer.exe", args);
113 #else
114 args << path;
115 QProcess::execute(
116 #if defined Q_OS_MAC
117 "/usr/bin/open",
118 #else
119 "/usr/bin/xdg-open",
120 #endif
121 args);
122 #endif
123 }
124 }