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@89
|
52 QStringList labels;
|
Chris@89
|
53 labels << tr("Modified files:")
|
Chris@89
|
54 << tr("Added files:")
|
Chris@89
|
55 << tr("Removed files:")
|
Chris@89
|
56 << tr("New untracked files:")
|
Chris@89
|
57 << tr("Missing files:");
|
Chris@89
|
58
|
Chris@89
|
59 QList<QListWidget **> lists;
|
Chris@89
|
60 lists << &m_modifiedList
|
Chris@89
|
61 << &m_addedList
|
Chris@89
|
62 << &m_removedList
|
Chris@89
|
63 << &m_unknownList
|
Chris@89
|
64 << &m_missingList;
|
Chris@89
|
65
|
Chris@89
|
66 for (int i = 0; i < labels.size(); ++i) {
|
Chris@89
|
67
|
Chris@89
|
68 QWidget *box = new QWidget;
|
Chris@89
|
69 QGridLayout *boxlayout = new QGridLayout;
|
Chris@89
|
70 box->setLayout(boxlayout);
|
Chris@89
|
71
|
Chris@89
|
72 boxlayout->addWidget(new QLabel(labels[i]), 0, 0);
|
Chris@89
|
73
|
Chris@89
|
74 *lists[i] = new QListWidget;
|
Chris@89
|
75 (*lists[i])->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@89
|
76 boxlayout->addWidget(*lists[i], 1, 0);
|
Chris@89
|
77
|
Chris@89
|
78 layout->addWidget(box, ++row, 0, 1, 2);
|
Chris@89
|
79 box->hide();
|
Chris@89
|
80 }
|
Chris@89
|
81
|
Chris@89
|
82 layout->setRowStretch(++row, 20);
|
Chris@88
|
83 }
|
Chris@88
|
84
|
Chris@93
|
85 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
86 {
|
Chris@93
|
87 delete m_dateReference;
|
Chris@93
|
88 }
|
Chris@93
|
89
|
Chris@88
|
90 void
|
Chris@88
|
91 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
92 {
|
Chris@88
|
93 m_localPath = p;
|
Chris@88
|
94 m_localPathLabel->setText(p);
|
Chris@93
|
95 delete m_dateReference;
|
Chris@93
|
96 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
97 if (!m_dateReference->exists() ||
|
Chris@93
|
98 !m_dateReference->isFile() ||
|
Chris@93
|
99 !m_dateReference->isReadable()) {
|
Chris@93
|
100 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
101 << m_dateReference->absoluteFilePath()
|
Chris@93
|
102 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
103 << endl;
|
Chris@93
|
104 delete m_dateReference;
|
Chris@93
|
105 m_dateReference = 0;
|
Chris@93
|
106 }
|
Chris@88
|
107 }
|
Chris@88
|
108
|
Chris@88
|
109 void
|
Chris@88
|
110 FileStatusWidget::setRemoteURL(QString r)
|
Chris@88
|
111 {
|
Chris@88
|
112 m_remoteURL = r;
|
Chris@88
|
113 m_remoteURLLabel->setText(r);
|
Chris@88
|
114 }
|
Chris@88
|
115
|
Chris@88
|
116 void
|
Chris@92
|
117 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
118 {
|
Chris@92
|
119 m_fileStates = p;
|
Chris@88
|
120 updateWidgets();
|
Chris@88
|
121 }
|
Chris@88
|
122
|
Chris@88
|
123 void
|
Chris@93
|
124 FileStatusWidget::highlightFile(QListWidget *w, int i)
|
Chris@93
|
125 {
|
Chris@93
|
126 DEBUG << "FileStatusWidget: highlighting file at " << i << endl;
|
Chris@93
|
127 QListWidgetItem *item = w->item(i);
|
Chris@93
|
128 item->setForeground(Qt::red);
|
Chris@93
|
129 //!!! and a nice gold star
|
Chris@93
|
130 }
|
Chris@93
|
131
|
Chris@93
|
132 void
|
Chris@88
|
133 FileStatusWidget::updateWidgets()
|
Chris@88
|
134 {
|
Chris@92
|
135 FileStates &sp = m_fileStates;
|
Chris@89
|
136 QMap<QStringList *, QListWidget *> listmap;
|
Chris@89
|
137 listmap[&sp.modified] = m_modifiedList;
|
Chris@89
|
138 listmap[&sp.added] = m_addedList;
|
Chris@89
|
139 listmap[&sp.removed] = m_removedList;
|
Chris@89
|
140 listmap[&sp.missing] = m_missingList;
|
Chris@89
|
141 listmap[&sp.unknown] = m_unknownList;
|
Chris@88
|
142
|
Chris@89
|
143 foreach (QStringList *sl, listmap.keys()) {
|
Chris@89
|
144 listmap[sl]->clear();
|
Chris@89
|
145 listmap[sl]->addItems(*sl);
|
Chris@89
|
146 listmap[sl]->parentWidget()->setVisible(!sl->empty());
|
Chris@89
|
147 }
|
Chris@93
|
148
|
Chris@93
|
149 if (m_dateReference) {
|
Chris@93
|
150 // Highlight untracked files that have appeared since the
|
Chris@93
|
151 // last interaction with the repo
|
Chris@93
|
152 QDateTime refTime = m_dateReference->lastModified();
|
Chris@93
|
153 DEBUG << "reference time: " << refTime << endl;
|
Chris@93
|
154 for (int i = 0; i < m_unknownList->count(); ++i) {
|
Chris@93
|
155 QString fn(m_localPath + "/" + m_unknownList->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@93
|
161 highlightFile(m_unknownList, i);
|
Chris@93
|
162 }
|
Chris@93
|
163 }
|
Chris@93
|
164 }
|
Chris@88
|
165 }
|
Chris@88
|
166
|