/**
 *
 * @param object
 * @param parent
 * @return
 */
ClassDialog::ClassDialog( Object *object, QWidget *parent) :
	KDialog(parent)
{
	m_object = object;
	setModal( false );

	showButtonOK( true );
	showButtonCancel( true );
	showButtonApply( false );

	m_tab = new KTabWidget( this );
	setMainWidget( m_tab );
	QWidget *widget = new QWidget( this );
	
	m_tab->addTab( widget, object->classInfo()->name() );
	
	
	//connect( this, SIGNAL(okClicked()), SLOT(slotOkClicked()) );

	QVBoxLayout *layout = new QVBoxLayout( widget );

	LabelsMetaInfo *labels = dynamic_cast<LabelsMetaInfo*>( object->classInfo()->metaInfo( "labels" ) );

	QLabel *label;
	label = new QLabel( widget );
	label->setAlignment( Qt::AlignCenter );
	if ( labels )
		label->setText( "<b>"  + labels->label( object->classInfo()->name() ) + "</b>" );
	else
		label->setText( "<b>" + object->classInfo()->name() + "</b>" );

	if ( labels )
		setCaption( labels->label( object->classInfo()->name() )  + " (" + oidToString(object->oid()) + ")" );
	else
		setCaption( object->classInfo()->name() + " (" + oidToString(object->oid()) + ")" );

	layout->addWidget( label );
	layout->addSpacing( 10 );

	QGridLayout *gridLayout = new QGridLayout( layout, object->numProperties() + object->numObjects() + object->numCollections(), 2, 5 );

	int row = 0;
	PropertiesIterator it( object->propertiesBegin() );
	PropertiesIterator end( object->propertiesEnd() );
	for ( ; it != end; ++it, ++row ) {
		Property p = *it;
		label = new QLabel( widget );
		if ( labels )
			label->setText( labels->label( p.name() ) );
		else
			label->setText( p.name() );
		gridLayout->addWidget( label, row, 0 );
		PropertyWidget *tmp = new PropertyWidget( p, widget );
		m_mapProperties.insert( p.name(), tmp );
		gridLayout->addWidget( tmp, row, 1 );
	}

	const ClassInfo *classInfo = object->classInfo();
	RelationInfosConstIterator it2( classInfo->relationsBegin() );
	RelationInfosConstIterator end2( classInfo->relationsEnd() );
	for ( ; it2 != end2; ++it2, ++row ) {
		RelationInfo *relObj = it2.data();
		label = new QLabel( widget );
		if ( labels )
			label->setText( labels->label( it2.data()->name() ) );
		else
			label->setText( it2.data()->name() );
		gridLayout->addWidget( label, row, 0 );

		QHBoxLayout *lay = new QHBoxLayout();
		gridLayout->addLayout( lay, row, 1 );
		KurlLabel *objLabel = new KurlLabel(widget);
		objLabel->setAlignment( Qt::AlignCenter );
		Object* obj = object->object( relObj->name() );
		updateObjectLabel( objLabel, obj );
		connect( objLabel, SIGNAL(leftClickedURL(const QString&)), SLOT(slotObjectSelected(const QString&)) );
		m_mapObjects.insert( relObj->name(), objLabel );
		QPushButton *but = new QPushButton( widget );
		but->setText( i18n( "Change" ) );
		connect( but, SIGNAL(clicked()), SLOT(slotChangeClicked()) );
		m_mapChangeButtons.insert( but, relObj );
		lay->addWidget( objLabel );
		lay->addWidget( but );

		Notifier *notifier = dynamic_cast<Notifier*>( Manager::self()->notificationHandler() );
//		if ( notifier && obj )
//			notifier->registerSlot( this, SLOT( slotObjectModified(const ClassInfo*,const OidType&,const PropertyInfo*,const QVariant&) ), 0, obj->oid() );
	}
	
	CollectionInfosConstIterator it3( classInfo->collectionsBegin() );
	CollectionInfosConstIterator end3( classInfo->collectionsEnd() );
	for ( ; it3 != end3; ++it3 ) {
		const CollectionInfo *info = it3.data();
		CollectionChooser *chooser = new CollectionChooser( m_tab );
		chooser->setObject( m_object );
		chooser->setCollectionName( info->name() );
		m_tab->addTab( chooser, info->name() );
	}
}
Exemple #2
0
DeviceConfigureDialog::DeviceConfigureDialog( const Medium &medium )
        : KDialogBase( amaroK::mainWindow(), "deviceconfiguredialog", true, QString("Select Plugin for " + medium.name()), Ok|Cancel, Ok, false )
{
    m_medium = new Medium( medium );
    kapp->setTopWidget( this );
    setCaption( kapp->makeStdCaption( i18n( "Configure Media Device" ) ) );
    showButtonApply( false );

    QVBox* vbox = makeVBoxMainWidget();
    vbox->setSpacing( KDialog::spacingHint() );

    QLabel *connectLabel = 0;
    m_connectEdit = 0;
    QLabel *disconnectLabel = 0;
    m_disconnectEdit = 0;
    m_transcodeCheck = 0;
    QButtonGroup *transcodeGroup = 0;
    m_transcodeAlways = 0;
    m_transcodeWhenNecessary = 0;
    m_transcodeRemove = 0;

    MediaDevice* device = MediaBrowser::instance()->deviceFromId( m_medium->id() );

    if( device )
    {
        device->loadConfig();

        // pre-connect/post-disconnect (mount/umount)
        connectLabel = new QLabel( vbox );
        connectLabel->setText( i18n( "Pre-&connect command:" ) );
        m_connectEdit = new HintLineEdit( device->m_preconnectcmd, vbox );
        m_connectEdit->setHint( i18n( "Example: mount %d" ) );
        connectLabel->setBuddy( m_connectEdit );
        QToolTip::add( m_connectEdit, i18n( "Set a command to be run before connecting to your device (e.g. a mount command) here.\n%d is replaced by the device node, %m by the mount point.\nEmpty commands are not executed." ) );

        disconnectLabel = new QLabel( vbox );
        disconnectLabel->setText( i18n( "Post-&disconnect command:" ) );
        m_disconnectEdit = new HintLineEdit( device->m_postdisconnectcmd, vbox );
        disconnectLabel->setBuddy( m_disconnectEdit );
        m_disconnectEdit->setHint( i18n( "Example: eject %d" ) );
        QToolTip::add( m_disconnectEdit, i18n( "Set a command to be run after disconnecting from your device (e.g. an eject command) here.\n%d is replaced by the device node, %m by the mount point.\nEmpty commands are not executed." ) );

        // transcode
        m_transcodeCheck = new QCheckBox( vbox );
        m_transcodeCheck->setText( i18n( "&Transcode before transferring to device" ) );
        m_transcodeCheck->setChecked( device->m_transcode );

        transcodeGroup = new QVButtonGroup( vbox );
        transcodeGroup->setTitle( i18n( "Transcode to preferred format for device" ) );
        m_transcodeAlways = new QRadioButton( transcodeGroup );
        m_transcodeAlways->setText( i18n( "Whenever possible" ) );
        m_transcodeAlways->setChecked( device->m_transcodeAlways );
        m_transcodeWhenNecessary = new QRadioButton( transcodeGroup );
        m_transcodeWhenNecessary->setText( i18n( "When necessary" ) );
        m_transcodeWhenNecessary->setChecked( !device->m_transcodeAlways );
        connect( m_transcodeCheck, SIGNAL(toggled( bool )),
                transcodeGroup, SLOT(setEnabled( bool )) );
        transcodeGroup->insert( m_transcodeAlways );
        transcodeGroup->insert( m_transcodeWhenNecessary );
        m_transcodeRemove = new QCheckBox( transcodeGroup );
        m_transcodeRemove->setText( i18n( "Remove transcoded files after transfer" ) );
        m_transcodeRemove->setChecked( device->m_transcodeRemove );

        const ScriptManager *sm = ScriptManager::instance();
        m_transcodeCheck->setEnabled( sm->transcodeScriptRunning() != QString::null );
        transcodeGroup->setEnabled( sm->transcodeScriptRunning() != QString::null && device->m_transcode );
        if( sm->transcodeScriptRunning().isNull() )
        {
            QToolTip::add( m_transcodeCheck, i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
            QToolTip::add( transcodeGroup, i18n( "For this feature, a script of type \"Transcode\" has to be running" ) );
        }

        device->addConfigElements( vbox );
    }

    m_accepted = false;
}