• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

vcs

vcseventwidget.cpp

00001 /***************************************************************************
00002  *   This file is part of KDevelop                                         *
00003  *   Copyright 2007 Dukju Ahn <dukjuahn@gmail.com>                         *
00004  *   Copyright 2007 Andreas Pakulat <apaku@gmx.de>                         *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License as       *
00008  *   published by the Free Software Foundation; either version 2 of the    *
00009  *   License, or (at your option) any later version.                       *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this program; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
00020  ***************************************************************************/
00021 
00022 #include "vcseventwidget.h"
00023 
00024 #include <QHeaderView>
00025 #include <QAction>
00026 
00027 #include <kdebug.h>
00028 #include <kmenu.h>
00029 
00030 
00031 #include <interfaces/iplugin.h>
00032 #include <interfaces/icore.h>
00033 #include <interfaces/iruncontroller.h>
00034 
00035 #include "ui_vcseventwidget.h"
00036 #include "vcsdiffwidget.h"
00037 
00038 #include "../vcsjob.h"
00039 #include "../interfaces/ibasicversioncontrol.h"
00040 #include "../vcsrevision.h"
00041 #include "../vcsevent.h"
00042 #include "../vcslocation.h"
00043 
00044 #include "../models/vcsitemeventmodel.h"
00045 #include "../models/vcseventmodel.h"
00046 
00047 
00048 namespace KDevelop
00049 {
00050 
00051 class VcsEventWidgetPrivate
00052 {
00053 public:
00054     VcsEventWidgetPrivate( VcsEventWidget* w )
00055         : q( w )
00056     {}
00057 
00058     Ui::VcsEventWidget* m_ui;
00059     VcsItemEventModel* m_detailModel;
00060     VcsEventModel *m_logModel;
00061     KDevelop::VcsJob* m_job;
00062     KUrl m_url;
00063     QModelIndex m_contextIndex;
00064     VcsEventWidget* q;
00065     void eventViewCustomContextMenuRequested( const QPoint &point );
00066     void eventViewClicked( const QModelIndex &index );
00067     void jobReceivedResults( KDevelop::VcsJob* job );
00068     void diffToPrevious();
00069     void diffRevisions();
00070 };
00071 
00072 void VcsEventWidgetPrivate::eventViewCustomContextMenuRequested( const QPoint &point )
00073 {
00074     m_contextIndex = m_ui->eventView->indexAt( point );
00075     if( !m_contextIndex.isValid() ){
00076         kDebug() << "contextMenu is not in TreeView";
00077         return;
00078     }
00079 
00080     KMenu menu( m_ui->eventView );
00081 
00082     QAction* action = menu.addAction(i18n("Diff to previous revision"));
00083     QObject::connect( action, SIGNAL(triggered(bool)), q, SLOT(diffToPrevious()) );
00084 
00085     action = menu.addAction(i18n("Diff between revisions"));
00086     QObject::connect( action, SIGNAL(triggered(bool)), q, SLOT(diffRevisions()) );
00087 
00088     menu.exec( m_ui->eventView->viewport()->mapToGlobal(point) );
00089 }
00090 
00091 void VcsEventWidgetPrivate::eventViewClicked( const QModelIndex &index )
00092 {
00093     KDevelop::VcsEvent ev = m_logModel->eventForIndex( index );
00094     if( ev.revision().revisionType() != KDevelop::VcsRevision::Invalid )
00095     {
00096         m_ui->message->setPlainText( ev.message() );
00097         m_detailModel->clear();
00098         m_detailModel->addItemEvents( ev.items() );
00099     }else
00100     {
00101         m_ui->message->clear();
00102         m_detailModel->clear();
00103     }
00104 }
00105 
00106 void VcsEventWidgetPrivate::jobReceivedResults( KDevelop::VcsJob* job )
00107 {
00108     if( job == m_job )
00109     {
00110         QList<QVariant> l = job->fetchResults().toList();
00111         QList<KDevelop::VcsEvent> newevents;
00112         foreach( QVariant v, l )
00113         {
00114             if( qVariantCanConvert<KDevelop::VcsEvent>( v ) )
00115             {
00116                 newevents << qVariantValue<KDevelop::VcsEvent>( v );
00117             }
00118         }
00119         m_logModel->addEvents( newevents );
00120     }
00121 }
00122 
00123 
00124 void VcsEventWidgetPrivate::diffToPrevious()
00125 {
00126     KDevelop::IPlugin* plugin = m_job->vcsPlugin();
00127     if( plugin )
00128     {
00129         KDevelop::IBasicVersionControl* iface = plugin->extension<KDevelop::IBasicVersionControl>();
00130         if( iface )
00131         {
00132             KDevelop::VcsEvent ev = m_logModel->eventForIndex( m_contextIndex );
00133             KDevelop::VcsRevision prev;
00134             prev.setRevisionValue( qVariantFromValue( KDevelop::VcsRevision::Previous ),
00135                                    KDevelop::VcsRevision::Special );
00136             KDevelop::VcsLocation loc( m_url );
00137 
00138             KDevelop::VcsJob* job = iface->diff( loc, loc, prev, ev.revision() );
00139 
00140             VcsDiffWidget* widget = new VcsDiffWidget( job );
00141             widget->setRevisions( prev, ev.revision() );
00142             KDialog* dlg = new KDialog( q );
00143             dlg->setCaption( i18n("Difference To Previous") );
00144             dlg->setButtons( KDialog::Ok );
00145             dlg->setMainWidget( widget );
00146             dlg->show();
00147         }
00148     }
00149 }
00150 
00151 void VcsEventWidgetPrivate::diffRevisions()
00152 {
00153     KDevelop::IPlugin* plugin = m_job->vcsPlugin();
00154     if( plugin )
00155     {
00156         KDevelop::IBasicVersionControl* iface = plugin->extension<KDevelop::IBasicVersionControl>();
00157         if( iface )
00158         {
00159             QModelIndexList l = m_ui->eventView->selectionModel()->selectedRows();
00160             KDevelop::VcsEvent ev1 = m_logModel->eventForIndex( l.first() );
00161             KDevelop::VcsEvent ev2 = m_logModel->eventForIndex( l.last() );
00162             KDevelop::VcsLocation loc( m_url );
00163             KDevelop::VcsJob* job = iface->diff( loc, loc, ev1.revision(), ev2.revision() );
00164 
00165             VcsDiffWidget* widget = new VcsDiffWidget( job );
00166             widget->setRevisions( ev1.revision(), ev2.revision() );
00167             KDialog* dlg = new KDialog( q );
00168             dlg->setCaption( i18n("Difference between Revisions") );
00169             dlg->setButtons( KDialog::Ok );
00170             dlg->setMainWidget( widget );
00171             dlg->show();
00172         }
00173     }
00174 }
00175 
00176 VcsEventWidget::VcsEventWidget( const KUrl& url, KDevelop::VcsJob *job, QWidget *parent )
00177     : QWidget(parent), d(new VcsEventWidgetPrivate(this) )
00178 {
00179 
00180     d->m_job = job;
00181     //Don't autodelete this job, its metadata will be used later on
00182     d->m_job->setAutoDelete( false );
00183 
00184     d->m_url = url;
00185     d->m_ui = new Ui::VcsEventWidget();
00186     d->m_ui->setupUi(this);
00187 
00188     d->m_logModel= new VcsEventModel(this);
00189     d->m_ui->eventView->setModel( d->m_logModel );
00190     d->m_ui->eventView->sortByColumn(0, Qt::DescendingOrder);
00191     d->m_ui->eventView->setContextMenuPolicy( Qt::CustomContextMenu );
00192     QHeaderView* header = d->m_ui->eventView->horizontalHeader();
00193     header->setResizeMode( 0, QHeaderView::ResizeToContents );
00194     header->setResizeMode( 1, QHeaderView::ResizeToContents );
00195     header->setResizeMode( 2, QHeaderView::ResizeToContents );
00196     header->setResizeMode( 3, QHeaderView::Stretch );
00197 
00198     d->m_detailModel = new VcsItemEventModel(this);
00199     d->m_ui->itemEventView->setModel( d->m_detailModel );
00200     header = d->m_ui->itemEventView->horizontalHeader();
00201     header->setResizeMode( 0, QHeaderView::ResizeToContents );
00202     header->setResizeMode( 1, QHeaderView::Stretch );
00203     header->setResizeMode( 2, QHeaderView::ResizeToContents );
00204     header->setResizeMode( 3, QHeaderView::Stretch );
00205     header->setResizeMode( 4, QHeaderView::ResizeToContents );
00206 
00207     connect( d->m_ui->eventView, SIGNAL( clicked( const QModelIndex& ) ),
00208              this, SLOT( eventViewClicked( const QModelIndex& ) ) );
00209     connect( d->m_ui->eventView, SIGNAL( customContextMenuRequested( const QPoint& ) ),
00210              this, SLOT( eventViewCustomContextMenuRequested( const QPoint& ) ) );
00211 
00212     connect( d->m_job, SIGNAL(resultsReady( KDevelop::VcsJob*) ),
00213              this, SLOT( jobReceivedResults( KDevelop::VcsJob* ) ) );
00214     ICore::self()->runController()->registerJob( d->m_job );
00215 }
00216 VcsEventWidget::~VcsEventWidget()
00217 {
00218     delete d->m_logModel;
00219     delete d->m_detailModel;
00220     delete d->m_ui;
00221     d->m_job->deleteLater();
00222     delete d;
00223 }
00224 
00225 }
00226 
00227 
00228 #include "vcseventwidget.moc"

vcs

Skip menu "vcs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal