Chris@88
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@88
|
2
|
Chris@88
|
3 /*
|
Chris@88
|
4 EasyMercurial
|
Chris@88
|
5
|
Chris@88
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@88
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@88
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@88
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@88
|
10
|
Chris@88
|
11 This program is free software; you can redistribute it and/or
|
Chris@88
|
12 modify it under the terms of the GNU General Public License as
|
Chris@88
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@88
|
14 License, or (at your option) any later version. See the file
|
Chris@88
|
15 COPYING included with this distribution for more information.
|
Chris@88
|
16 */
|
Chris@88
|
17
|
Chris@88
|
18 #include "filestatuswidget.h"
|
Chris@88
|
19
|
Chris@88
|
20 #include <QLabel>
|
Chris@88
|
21 #include <QListWidget>
|
Chris@88
|
22 #include <QGridLayout>
|
Chris@93
|
23 #include <QFileInfo>
|
Chris@93
|
24 #include <QApplication>
|
Chris@93
|
25 #include <QDateTime>
|
Chris@93
|
26
|
Chris@93
|
27 #include "debug.h"
|
Chris@88
|
28
|
Chris@88
|
29 FileStatusWidget::FileStatusWidget(QWidget *parent) :
|
Chris@93
|
30 QWidget(parent),
|
Chris@93
|
31 m_dateReference(0)
|
Chris@88
|
32 {
|
Chris@88
|
33 QGridLayout *layout = new QGridLayout;
|
Chris@88
|
34 setLayout(layout);
|
Chris@88
|
35
|
Chris@88
|
36 int row = 0;
|
Chris@88
|
37
|
Chris@88
|
38 layout->addWidget(new QLabel(tr("Local:")), row, 0);
|
Chris@88
|
39 m_localPathLabel = new QLabel;
|
Chris@89
|
40 QFont f(m_localPathLabel->font());
|
Chris@89
|
41 f.setBold(true);
|
Chris@89
|
42 m_localPathLabel->setFont(f);
|
Chris@88
|
43 layout->addWidget(m_localPathLabel, row, 1);
|
Chris@88
|
44
|
Chris@88
|
45 ++row;
|
Chris@88
|
46 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
|
Chris@88
|
47 m_remoteURLLabel = new QLabel;
|
Chris@88
|
48 layout->addWidget(m_remoteURLLabel, row, 1);
|
Chris@88
|
49
|
Chris@89
|
50 layout->setColumnStretch(1, 20);
|
Chris@88
|
51
|
Chris@94
|
52 QMap<FileStates::State, QString> labels;
|
Chris@94
|
53 labels[FileStates::Clean] = tr("Unmodified files:");
|
Chris@94
|
54 labels[FileStates::Modified] = tr("Modified files:");
|
Chris@94
|
55 labels[FileStates::Added] = tr("Added files:");
|
Chris@94
|
56 labels[FileStates::Removed] = tr("Removed files:");
|
Chris@94
|
57 labels[FileStates::Missing] = tr("Missing files:");
|
Chris@94
|
58 labels[FileStates::Unknown] = tr("Untracked files:");
|
Chris@89
|
59
|
Chris@94
|
60 for (int i = int(FileStates::FirstState);
|
Chris@94
|
61 i <= int(FileStates::LastState); ++i) {
|
Chris@89
|
62
|
Chris@94
|
63 FileStates::State s = FileStates::State(i);
|
Chris@89
|
64
|
Chris@89
|
65 QWidget *box = new QWidget;
|
Chris@89
|
66 QGridLayout *boxlayout = new QGridLayout;
|
Chris@89
|
67 box->setLayout(boxlayout);
|
Chris@89
|
68
|
Chris@94
|
69 boxlayout->addWidget(new QLabel(labels[s]), 0, 0);
|
Chris@89
|
70
|
Chris@94
|
71 QListWidget *w = new QListWidget;
|
Chris@94
|
72 m_stateListMap[s] = w;
|
Chris@94
|
73 w->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@94
|
74 boxlayout->addWidget(w, 1, 0);
|
Chris@89
|
75
|
Chris@89
|
76 layout->addWidget(box, ++row, 0, 1, 2);
|
Chris@89
|
77 box->hide();
|
Chris@89
|
78 }
|
Chris@89
|
79
|
Chris@89
|
80 layout->setRowStretch(++row, 20);
|
Chris@88
|
81 }
|
Chris@88
|
82
|
Chris@93
|
83 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
84 {
|
Chris@93
|
85 delete m_dateReference;
|
Chris@93
|
86 }
|
Chris@93
|
87
|
Chris@94
|
88 void FileStatusWidget::clearSelections()
|
Chris@94
|
89 {
|
Chris@94
|
90 foreach (QListWidget *w, m_stateListMap) {
|
Chris@94
|
91 w->clearSelection();
|
Chris@94
|
92 }
|
Chris@94
|
93 }
|
Chris@94
|
94
|
Chris@88
|
95 void
|
Chris@88
|
96 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
97 {
|
Chris@88
|
98 m_localPath = p;
|
Chris@88
|
99 m_localPathLabel->setText(p);
|
Chris@93
|
100 delete m_dateReference;
|
Chris@93
|
101 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
102 if (!m_dateReference->exists() ||
|
Chris@93
|
103 !m_dateReference->isFile() ||
|
Chris@93
|
104 !m_dateReference->isReadable()) {
|
Chris@93
|
105 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
106 << m_dateReference->absoluteFilePath()
|
Chris@93
|
107 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
108 << endl;
|
Chris@93
|
109 delete m_dateReference;
|
Chris@93
|
110 m_dateReference = 0;
|
Chris@93
|
111 }
|
Chris@88
|
112 }
|
Chris@88
|
113
|
Chris@88
|
114 void
|
Chris@88
|
115 FileStatusWidget::setRemoteURL(QString r)
|
Chris@88
|
116 {
|
Chris@88
|
117 m_remoteURL = r;
|
Chris@88
|
118 m_remoteURLLabel->setText(r);
|
Chris@88
|
119 }
|
Chris@88
|
120
|
Chris@88
|
121 void
|
Chris@92
|
122 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
123 {
|
Chris@92
|
124 m_fileStates = p;
|
Chris@88
|
125 updateWidgets();
|
Chris@88
|
126 }
|
Chris@88
|
127
|
Chris@88
|
128 void
|
Chris@93
|
129 FileStatusWidget::highlightFile(QListWidget *w, int i)
|
Chris@93
|
130 {
|
Chris@93
|
131 DEBUG << "FileStatusWidget: highlighting file at " << i << endl;
|
Chris@93
|
132 QListWidgetItem *item = w->item(i);
|
Chris@93
|
133 item->setForeground(Qt::red);
|
Chris@93
|
134 //!!! and a nice gold star
|
Chris@93
|
135 }
|
Chris@93
|
136
|
Chris@93
|
137 void
|
Chris@88
|
138 FileStatusWidget::updateWidgets()
|
Chris@88
|
139 {
|
Chris@94
|
140 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@94
|
141 QListWidget *w = m_stateListMap[s];
|
Chris@94
|
142 w->clear();
|
Chris@94
|
143 QStringList sl = m_fileStates.getFilesInState(s);
|
Chris@94
|
144 w->addItems(sl);
|
Chris@94
|
145 w->parentWidget()->setVisible(!sl.empty());
|
Chris@89
|
146 }
|
Chris@93
|
147
|
Chris@93
|
148 if (m_dateReference) {
|
Chris@93
|
149 // Highlight untracked files that have appeared since the
|
Chris@93
|
150 // last interaction with the repo
|
Chris@93
|
151 QDateTime refTime = m_dateReference->lastModified();
|
Chris@93
|
152 DEBUG << "reference time: " << refTime << endl;
|
Chris@94
|
153 QListWidget *ul = m_stateListMap[FileStates::Unknown];
|
Chris@94
|
154 for (int i = 0; i < ul->count(); ++i) {
|
Chris@94
|
155 QString fn(m_localPath + "/" + ul->item(i)->text());
|
Chris@93
|
156 DEBUG << "comparing with " << fn << endl;
|
Chris@93
|
157 QFileInfo fi(fn);
|
Chris@93
|
158 if (fi.exists() && fi.lastModified() > refTime) {
|
Chris@93
|
159 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
|
Chris@93
|
160 << ") than reference" << endl;
|
Chris@94
|
161 highlightFile(ul, i);
|
Chris@93
|
162 }
|
Chris@93
|
163 }
|
Chris@93
|
164 }
|
Chris@88
|
165 }
|
Chris@88
|
166
|