summaryrefslogtreecommitdiffstats
path: root/vcs/subversion/svn_blamewidget.cpp
blob: 5d1861774ca96ad12e08c7fbe52552ef1301e9ff (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
/*
 *  Copyright (C) 2007 Dukju Ahn (dukjuahn@gmail.com)
 *
 *  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.
 */

#include "svn_blamewidget.h"
#include "subversion_widget.h"
#include <qmap.h>
#include <qlistview.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qstringlist.h>
#include <qfont.h>

#include <klocale.h>
#include <kmessagebox.h>

SvnBlameWidget::SvnBlameWidget( QWidget *parent, const char* name, bool modal, WFlags f )
	:QWidget( parent )
{
    m_layout = new QVBoxLayout( this, 1, 1 );
    m_layout->setMargin(1);
    
    m_listView = new QListView( this );
    outView()->setAllColumnsShowFocus( TRUE );
    outView()->addColumn( i18n("Line") );
    outView()->addColumn( i18n("Rev") );
    outView()->addColumn( i18n("Date") );
    outView()->addColumn( i18n("Author") );
    outView()->addColumn( i18n("Content") );
    
    m_layout->addWidget( m_listView );
}
SvnBlameWidget::~SvnBlameWidget()
{}

void SvnBlameWidget::copyBlameData( QValueList<SvnBlameHolder> *blamelist )
{
	m_blamelist = *blamelist;
}
	
void SvnBlameWidget::show()
{
	outView()->clear();
	outView()->setSortColumn(0);
	
	QFont f = outView()->font();
	f.setFixedPitch( true );
	outView()->setFont( f );

	QValueList<SvnBlameHolder>::Iterator it;
	
	for( it = m_blamelist.begin(); it != m_blamelist.end(); ++it ){
		
		SvnBlameHolder holder = *it;
		SvnIntSortListItem *item = new SvnIntSortListItem(outView());
		
		QString prettyDate = holder.date.left(16).replace(10, 1, ' ');
		
		item->setText(0, QString::number( holder.line+1 ) ); 
		item->setText(1, QString::number(holder.rev) );
		item->setText(2, prettyDate );
		item->setText(3, holder.author );
		item->setText(4, holder.content );
		
	}
	outView()->sort();
	QWidget::show();
}

QListView* SvnBlameWidget::outView()
{
    return m_listView;
}

/////////////////////////////////////////////////////////////

SvnBlameFileSelectDlg::SvnBlameFileSelectDlg( QWidget *parent )
    : QDialog( parent )
{
    m_selected = "";
    setCaption( i18n("Select one file to view annotation") );
    
    m_layout = new QGridLayout( this, 2, 2 );
    m_view = new QListView( this );
    m_view->addColumn( i18n("files") );
    m_okBtn = new QPushButton( i18n("OK"), this );
    m_cancelBtn = new QPushButton( i18n("Cancel"), this );
    m_layout->addMultiCellWidget( m_view, 0, 0, 0, 1 );
    m_layout->addWidget( m_okBtn, 1, 0 );
    m_layout->addWidget( m_cancelBtn, 1, 1 );
    
    connect( m_okBtn, SIGNAL(clicked()), this, SLOT(accept()) );
    connect( m_cancelBtn, SIGNAL(clicked()), this, SLOT(reject()) );
}
SvnBlameFileSelectDlg::~SvnBlameFileSelectDlg()
{}

void SvnBlameFileSelectDlg::setCandidate( QStringList *list )
{
    for( QValueList<QString>::iterator it = list->begin(); it != list->end(); ++it ){
        QListViewItem *item = new QListViewItem( m_view, *it );
    }
}

QString SvnBlameFileSelectDlg::selected()
{
    return m_selected;
}

void SvnBlameFileSelectDlg::accept()
{
    while( true ){
        QListViewItem *item = m_view->currentItem();
        if( item ){
            m_selected = item->text(0);
            break;
        }
        else{
            KMessageBox::error( this, i18n("Select file from list to view annotation") );
        }
    }
    QDialog::accept();
}

#include "svn_blamewidget.moc"