summaryrefslogtreecommitdiffstats
path: root/vcs/subversion/svn_logviewwidget.cpp
blob: c6aae45241b5f730259a633812f16cef4ad77e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
 *  Copyright (C) 2007 Dukju Ahn ([email protected])
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *
 */

#include "svn_logviewwidget.h"
#include "svn_blamewidget.h"
#include "subversion_core.h"
#include "subversion_global.h"
#include <kdevproject.h>
#include <ktextedit.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <klocale.h>
#include <qradiobutton.h>
#include <qcombobox.h>
#include <knuminput.h>
#include <qcheckbox.h>

#include <qsplitter.h>
#include <qheader.h>
#include <qlistview.h>
#include <qlayout.h>
#include <qstringlist.h>

SvnLogViewWidget::SvnLogViewWidget(subversionPart *part, QWidget *parent)
	:QWidget(parent), m_part(part)
{
    m_layout = new QGridLayout( this, 1, 1, 11, 6, "SvnLogViewWidgetBaseLayout");

    splitter1 = new QSplitter( this, "splitter1" );
    splitter1->setOrientation( QSplitter::Horizontal );
    splitter1->setMargin(1);

    listView1 = new QListView( splitter1, "listView1" );
    listView1->addColumn( i18n( "Rev" ) );
    listView1->addColumn( i18n( "Date" ) );
    listView1->addColumn( i18n( "Author" ) );
    listView1->addColumn( i18n( "Comment" ) );
    listView1->resize( QSize(1, 1).expandedTo(minimumSizeHint()) );
    QFont listView1_font(  listView1->font() );
    listView1_font.setPointSize( 9 );
    listView1->setFont( listView1_font );
    listView1->setAllColumnsShowFocus( TRUE );
    listView1->setShowSortIndicator( TRUE );

    textEdit1 = new KTextEdit( splitter1, "textEdit1" );
    textEdit1->resize( QSize(1, 1).expandedTo(minimumSizeHint()) );
    QFont textEdit1_font(  textEdit1->font() );
    textEdit1_font.setPointSize( 9 );
    textEdit1->setFont( textEdit1_font );
    textEdit1->setFocusPolicy( QTextEdit::WheelFocus );
    textEdit1->setReadOnly( TRUE );

    m_layout->addWidget( splitter1, 0, 0 );
    m_layout->setMargin(1);

    resize( QSize(692, 343).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
    
	connect( listView1, SIGNAL(clicked( QListViewItem *)), this, SLOT(slotClicked(QListViewItem*)) );
    connect( listView1, SIGNAL(contextMenuRequested( QListViewItem*, const QPoint&, int )),
             this, SLOT(contextMenuRequested(QListViewItem*, const QPoint&, int)) );
}
SvnLogViewWidget::~SvnLogViewWidget()
{
}

void SvnLogViewWidget::setLogResult( QValueList<SvnLogHolder> *loglist )
{
	this->listView1->clear();
	this->textEdit1->clear();
	this->listView1->setSorting( 1, false );
	
	for( QValueList<SvnLogHolder>::Iterator it=loglist->begin(); it!=loglist->end(); ++it ){
		
		SvnLogHolder holder = *it;
		SvnLogViewItem *item = new SvnLogViewItem(this->listView1);
		
		QString prettyDate = holder.date.left(16).replace(10, 1, ' ');
		
		item->setText(0, holder.rev );
		item->setText(1, prettyDate );
		item->setText(2, holder.author );
		item->setText(3, holder.logMsg.simplifyWhiteSpace() );
		
		item->m_pathList = holder.pathList;
		item->m_message = holder.logMsg;
	}
// 	this->listView1->show();
}

void SvnLogViewWidget::setRequestedUrl( QString reqUrl )
{
	m_reqUrl = reqUrl;
}

void SvnLogViewWidget::slotClicked( QListViewItem *oneItem )
{
	if( !oneItem ) return;
	SvnLogViewItem *item = dynamic_cast<SvnLogViewItem*>( oneItem );
    if( !item ) return;
	textEdit1->clear();
	textEdit1->append( item->m_pathList );
	textEdit1->append( "\n\n" );
	textEdit1->append( item->m_message + "\n" );
}
void SvnLogViewWidget::contextMenuRequested( QListViewItem *item, const QPoint & pos, int col )
{
    if( !item || col == -1 )
        return;
    m_ctxLogItem = dynamic_cast<SvnLogViewItem*>(item);
    if( !m_ctxLogItem )
        return;
    QPopupMenu *menu = new QPopupMenu(this);
    menu->insertItem( i18n("Blame this revision"), this, SLOT(blameThis()) );
    menu->insertItem( i18n("Difference to previous revision"), this, SLOT(diffToPrevious()) );
    menu->exec( pos );
}
void SvnLogViewWidget::blameThis()
{
	if( !m_ctxLogItem ){
		KMessageBox::error( this, i18n("No revision was clicked"), i18n("error") );
		return;
	}
	// note that blame is done on single file.
	QStringList modifies = QStringList::split( "\n", m_ctxLogItem->m_pathList, false );
	QString selectedPath;
	if( modifies.count() > 1 ){
		SvnBlameFileSelectDlg dlg(this);
		dlg.setCandidate( &modifies );
		if( dlg.exec() == QDialog::Accepted ){
			selectedPath = dlg.selected();
		} else{
			return;
		}
		
	} else if( modifies.count() == 1 ){
		selectedPath = *( modifies.at(0) );
	} else {
		return;
	}
	
	QString relPath = selectedPath.section( '/', 1 );
	
	QValueList< SvnGlobal::SvnInfoHolder > holderList = m_part->m_prjInfoMap.values();
	SvnGlobal::SvnInfoHolder holder;
	if( holderList.count() > 0 ){
		// get full Url
		holder = holderList.first();
		QString absPath =  holder.reposRootUrl.url(-1) + '/' + relPath;
		kdDebug(9036) << " Blame requested on path " << absPath << endl;
		// get revision
		int revEnd = m_ctxLogItem->text(0).toInt();
		// final request
		m_part->svncore()->blame( KURL(absPath), SvnGlobal::dont_touch, 0, "", revEnd, "" );
	}
	else{
		return;
	}
}

void SvnLogViewWidget::diffToPrevious()
{
    if( !m_ctxLogItem ){
        KMessageBox::error( this, i18n("No revision was clicked"), i18n("error") );
        return;
    }
    int revThis = m_ctxLogItem->text(0).toInt();
	int revPrev = revThis - 1;
	kdDebug(9036) << " Diff to prev requested on " << m_reqUrl << endl;
	m_part->svncore()->diffAsync( m_reqUrl, m_reqUrl, revPrev, "", revThis, "",
	 				true/*recurse*/, true/*peg_diff*/ );
}

SvnLogViewOptionDlg::SvnLogViewOptionDlg( QWidget *parent, const char* name, bool modal, WFlags f )
: SvnLogViewOptionDlgBase( parent, name, modal,f )
{
// 	radio1->setChecked(true); //repository log
	radio4->setChecked(true); //start revistion by revision keyword
	radio5->setChecked(true); //end revision by revision number
	reinstallRevisionSpecifiers();
	connect( intInput1, SIGNAL(valueChanged(int)), this, SLOT(setStartRevnumRadio()) );
	connect( comboBox1, SIGNAL(activated(const QString&)), this, SLOT(setStartRevkindRadio()) );
	connect( intInput2, SIGNAL(valueChanged(int)), this, SLOT(setEndRevnumRadio()) );
	connect( comboBox2, SIGNAL(activated(const QString&)), this, SLOT(setEndRevkindRadio()) );
}
SvnLogViewOptionDlg::~SvnLogViewOptionDlg()
{}
void SvnLogViewOptionDlg::reinstallRevisionSpecifiers()
{
	comboBox1->clear();
	comboBox2->clear();

	QStringList items;
	items << "HEAD" << "BASE" << "PREV" << "COMMITTED";
	comboBox1->insertStringList( items );
	comboBox2->insertStringList( items );
}
int SvnLogViewOptionDlg::revstart()
{
	if( !radio3->isChecked() ){
		return -1;
	} else{
		return intInput1->value();
	}
}
QString SvnLogViewOptionDlg::revKindStart()
{
	if( !radio4->isChecked() ){
		return QString("");
	} else{
		return comboBox1->currentText();
	}
}
int SvnLogViewOptionDlg::revend()
{
	if( !radio5->isChecked() ){
		return -1;
	} else{
		return intInput2->value();
	}
}
QString SvnLogViewOptionDlg::revKindEnd()
{
	if( !radio6->isChecked() ){
		return QString("");
	} else{
		return comboBox2->currentText();
	}
}
bool SvnLogViewOptionDlg::strictNode()
{
	if( checkBox1->isChecked() ){
		return true;
	} else{
		return false;
	}
}
void SvnLogViewOptionDlg::setStartRevnumRadio()
{
	radio3->setChecked(true);
}
void SvnLogViewOptionDlg::setStartRevkindRadio()
{
	radio4->setChecked(true);
}
void SvnLogViewOptionDlg::setEndRevnumRadio()
{
	radio5->setChecked(true);
}
void SvnLogViewOptionDlg::setEndRevkindRadio()
{
	radio6->setChecked(true);
}

#include "svn_logviewwidget.moc"