2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "CommitsCursor.h"
20 #include "CommitsMatcher.h"
24 CommitsCursor::CommitsCursor(SelectionType selectionType
)
29 m_firstInBranch(m_head
.firstCommitInBranch()),
30 m_done(! m_head
.isValid()),
32 m_selectionType(selectionType
)
36 CommitsCursor::~CommitsCursor()
41 int CommitsCursor::forward(Scope scope
, bool skipAnswered
)
44 Q_UNUSED(skipAnswered
);
45 // go to a parent commit
46 int newIndex
= m_currentIndex
;
47 if (m_current
.previousCommitsCount() > 0) {
48 Commit parent
= m_current
.previous()[0];
50 if (! parent
.isValid())
51 return m_currentIndex
;
53 CommitsMatcher::ExpectedAction action
= CommitsMatcher::ShowPatch
;
55 action
= m_matcher
->match(parent
);
56 if (action
== CommitsMatcher::ShowPatch
) {
58 m_currentIndex
= newIndex
;
61 if (action
== CommitsMatcher::Exit
) {
63 return m_currentIndex
;
65 if (parent
.previousCommitsCount() == 0) {// no more commits;
67 return m_currentIndex
;
69 parent
= parent
.previous()[0];
72 return m_currentIndex
;
75 int CommitsCursor::back(Scope scope
)
78 Commit c
= m_current
.next();
79 int newIndex
= m_currentIndex
;
82 return m_currentIndex
;
84 CommitsMatcher::ExpectedAction action
= CommitsMatcher::ShowPatch
;
86 action
= m_matcher
->match(c
);
87 if (action
== CommitsMatcher::ShowPatch
) {
89 if (m_current
== m_firstInBranch
)
91 m_currentIndex
= newIndex
;
92 return m_currentIndex
;
94 if (action
== CommitsMatcher::Exit
) {
96 return m_currentIndex
;
102 void CommitsCursor::setResponse(bool response
, Scope scope
)
105 m_current
.setAcceptance(response
? Vng::Accepted
: Vng::Rejected
);
106 if ((m_selectionType
== SelectRange
&& !response
)
107 || (m_selectionType
== SelectOnePatch
&& response
)) // exit when user says 'no'
109 m_oldestIndex
= qMax(m_oldestIndex
, m_currentIndex
);
112 int CommitsCursor::count()
114 return -1; // TODO we _can_ count.. Its just not quite useful in most cases.
117 void CommitsCursor::forceCount()
119 // TODO sure you want to do that??
122 QString
CommitsCursor::currentText() const
124 return QString("\n") +
125 m_current
.commitTime().toString() + QString(" ") + m_current
.author() + QString("\n ") +
126 m_current
.logMessage();
129 QString
CommitsCursor::helpMessage() const
132 "How to use unrecord...\n"
133 "y: unrecord this patch\n"
134 "n: don't unrecord it\n\n"
135 // "v: view this patch in full with pager\n"
136 // "x: view a summary of this patch\n"
137 "d: unrecord selected patches\n"
138 "q: cancel unrecord\n\n"
139 "j: skip to next patch\n"
140 "k: back up to previous patch\n"
141 "c: calculate number of patches\n"
142 "h or ?: show this help\n");
145 bool CommitsCursor::isValid() const
147 return !m_done
&& m_current
.previousCommitsCount() > 0;
150 QString
CommitsCursor::allowedOptions() const
152 QString allowed
= "ynq";
153 if (m_selectionType
== SelectRange
)
155 // if (m_total == -1)
160 Commit
CommitsCursor::head()
165 void CommitsCursor::setUseMatcher(bool use
)
174 m_matcher
= new CommitsMatcher();