//
// QPerforce is a gui interface to the perforce revision control
// system. It is based on the qt library, and should be easily portable
// across any platform that has this toolkit available.
//
// Copyright (C) 2002 Jacob Gladish
//
#include "LabelMenu.h"
#include "ImageManager.h"
#include "ServerThread.h"
#include "todo.h"
#include <qradiobutton.h>
#include <qbuttongroup.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define ADD_BUTTON_TO_GROUP( B, G, POPUP )\
G->insert(B);\
POPUP->insertItem(B);
LabelMenu::LabelMenu( QWidget* parent, const char* name ) :
QPopupMenu( parent, name )
{
insertItem( "New...", this, SLOT(slotNew()) );
insertItem( "Edit Spec...", this, SLOT(slotEditSpec()) );
insertItem( "Describe...", this, SLOT(slotDescribe()) );
insertItem( "Delete", this, SLOT(slotDelete()) );
insertSeparator();
insertItem( "Create or Update Label from Template", this,
SLOT(slotCreateOrUpdateLabelFromTemplate()) );
insertSeparator();
insertItem( "List Files at Label", this, SLOT(slotListFilesAtLabel()) );
insertItem( "Add/Replace Files Listed in Label...", this,
SLOT(slotAddReplaceFilesListedInLabel()) );
insertItem( "Delete Some Files Listed in Label...", this,
SLOT(slotDeleteSomeFilesListedInLabel()) );
insertItem( "Sync Specified Files in Label to Client...", this,
SLOT(slotSyncSpecifiedFilesInLabelToClient()) );
insertSeparator();
// TODO make radio buttons
insertItem( "Unfiltered Labels", this, SLOT(slotUnfilteredLabels()) );
insertItem( "Filetered Labels for Selected Files", this,
SLOT(slotFilteredLabelsFromSelectedFiles()) );
insertSeparator();
//======================================================================
// Select the default action for DND. Radio Buttons...
//
_defaultDNDAction = new QPopupMenu();
_dndDefaultActions = new QButtonGroup( _defaultDNDAction );
QObject::connect( _dndDefaultActions, SIGNAL(clicked(int)),
this, SLOT(slotSetDefaultDNDAction(int)) );
_addReplace = new QRadioButton( "Add/Replace Files Listed in Label",
_dndDefaultActions );
ADD_BUTTON_TO_GROUP( _addReplace, _dndDefaultActions, _defaultDNDAction );
_delete = new QRadioButton( "Delete Some Files Listed in Label",
_dndDefaultActions );
ADD_BUTTON_TO_GROUP( _delete, _dndDefaultActions, _defaultDNDAction );
_sync = new QRadioButton( "Sycn Specified Files in Label to Client",
_dndDefaultActions );
ADD_BUTTON_TO_GROUP( _sync, _dndDefaultActions, _defaultDNDAction );
_filter = new QRadioButton( "Filter Labels For Selected Files",
_dndDefaultActions );
ADD_BUTTON_TO_GROUP( _filter, _dndDefaultActions, _defaultDNDAction );
_show = new QRadioButton( "Show Drag ang Drop Menu", _dndDefaultActions );
ADD_BUTTON_TO_GROUP( _show, _dndDefaultActions, _defaultDNDAction );
insertItem( "Default drag and drop action", _defaultDNDAction );
//======================================================================
insertItem( "View Labels", this, SLOT(slotViewLabels()) );
}
LabelMenu::~LabelMenu()
{
}
void LabelMenu::slotNew()
{
TODO();
}
void LabelMenu::slotEditSpec()
{
TODO();
}
void LabelMenu::slotDescribe()
{
TODO();
}
void LabelMenu::slotDelete()
{
TODO();
}
void LabelMenu::slotCreateOrUpdateLabelFromTemplate()
{
TODO();
}
void LabelMenu::slotListFilesAtLabel()
{
TODO();
}
void LabelMenu::slotAddReplaceFilesListedInLabel()
{
TODO();
}
void LabelMenu::slotDeleteSomeFilesListedInLabel()
{
TODO();
}
void LabelMenu::slotSyncSpecifiedFilesInLabelToClient()
{
TODO();
}
void LabelMenu::slotUnfilteredLabels()
{
TODO();
}
void LabelMenu::slotFilteredLabelsFromSelectedFiles()
{
TODO();
}
void LabelMenu::slotAddRepalceFilesListedInLabel()
{
TODO();
}
void LabelMenu::slotShowDragAndDropMenu()
{
TODO();
}
void LabelMenu::slotSetDefaultDNDAction( int n )
{
qDebug( "New Drag-N-Drop action selected: %d.", n );
TODO();
}
void LabelMenu::setListView( LabelTable* view )
{
ASSERT( view != NULL );
_myView = view;
}
void LabelMenu::slotViewLabels()
{
ServerThread< LabelMenu, LabelMenuFuncPtr >* t =
new ServerThread< LabelMenu, LabelMenuFuncPtr >
( this, &LabelMenu::_viewLabels );
}
void LabelMenu::_viewLabels()
{
ASSERT( _myView != NULL );
_myView->clear();
Perforce::LabelList labels = Perforce::Label::getLabels();
for (Perforce::Label* l = labels.first(); l != NULL; l = labels.next()) {
ASSERT( l != NULL );
_myView->addLabel( l );
}
qDebug( "signal emit showLabels( LABEL_TABLE )" );
emit showLabels( LABEL_TABLE );
}
//========================================================================
// The Widget to display the Labels.
//
LabelTable::LabelTable( QWidget* parent, const char* name ) :
QListView( parent, name )
{
setSelectionMode( Single );
setAllColumnsShowFocus( true );
addColumn( "Label" );
addColumn( "Owner" );
addColumn( "Lock" );
addColumn( "Date" );
addColumn( "Description" );
}
void LabelTable::addLabel( const Perforce::Label* l )
{
ASSERT( l != NULL );
QListViewItem* item = new QListViewItem(
this,
l->getName(),
l->getOwner(),
l->getStatus(),
l->getDate().toString(),
l->getDescription()
);
item->setPixmap( 0, ImageManager::getInstance()->getPixmap("label.png") );
}