summaryrefslogtreecommitdiffstats
path: root/krecipes/src/dialogs/dependanciesdialog.cpp
blob: b520d77427b149ed0af5c9db13de6ea8e015e686 (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
/***************************************************************************
*   Copyright (C) 2003 by                                                 *
*   Unai Garro (ugarro@users.sourceforge.net)                             *
*   Cyril Bosselut (bosselut@b1project.com)                               *
*                                                                         *
*   Copyright (C) 2003-2005 by                                            *
*   Jason Kivlighn (jkivlighn@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.                                   *
***************************************************************************/

#include "dependanciesdialog.h"
#include "datablocks/elementlist.h"

#include <ntqvbox.h>

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

DependanciesDialog::DependanciesDialog( TQWidget *parent, const TQValueList<ListInfo> &lists, bool deps_are_deleted ) : KDialogBase( parent, "DependanciesDialog", true, TQString::null,
	  KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel ),
	  m_depsAreDeleted(deps_are_deleted)
{
	init( lists );
}

DependanciesDialog::DependanciesDialog( TQWidget *parent, const ListInfo &list, bool deps_are_deleted ) : KDialogBase( parent, "DependanciesDialog", true, TQString::null,
	  KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel ),
	  m_depsAreDeleted(deps_are_deleted)
{
	TQValueList<ListInfo> lists;
	lists << list;
	init( lists );
}

DependanciesDialog::~DependanciesDialog()
{}	

void DependanciesDialog::init( const TQValueList<ListInfo> &lists )
{
	TQVBox *page = makeVBoxMainWidget();

	// Design the dialog

	instructionsLabel = new TQLabel( page );
	instructionsLabel->setMinimumSize( TQSize( 100, 30 ) );
	instructionsLabel->setMaximumSize( TQSize( 10000, 10000 ) );
	instructionsLabel->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignVCenter ) );
	
	if ( m_depsAreDeleted ) {
		instructionsLabel->setText( i18n( "<b>WARNING:</b> The following will have to be removed also, since currently they use the element you have chosen to be removed." ) );
	}
	else {
		instructionsLabel->setText( i18n( "<b>WARNING:</b> The following currently use the element you have chosen to be removed." ) );
	}

	for ( TQValueList<ListInfo>::const_iterator list_it = lists.begin(); list_it != lists.end(); ++list_it ) {
		if ( !((*list_it).list).isEmpty() ) {
			TQGroupBox *groupBox = new TQGroupBox( 1, TQt::Vertical, (*list_it).name, page );
			KListBox *listBox = new KListBox( groupBox );
			loadList( listBox, (*list_it).list );
		}
	}

	setSizeGripEnabled( true );
}

void DependanciesDialog::loadList( KListBox* listBox, const ElementList &list )
{
	KConfig * config = KGlobal::config();
	config->setGroup( "Advanced" );
	bool show_id = config->readBoolEntry( "ShowID", false );

	for ( ElementList::const_iterator el_it = list.begin(); el_it != list.end(); ++el_it ) {
		TQString name = ( *el_it ).name;
		if ( show_id )
			name += " (" + TQString::number(( *el_it ).id) + ")";
		listBox->insertItem( name );
	}
}

void DependanciesDialog::accept()
{
	if ( !m_msg.isEmpty() ) {
		switch ( KMessageBox::warningYesNo(this,
			TQString("<b>%1</b><br><br>%2").arg(m_msg).arg(i18n("Are you sure you wish to proceed?")),
			TQString::null,KStdGuiItem::yes(),KStdGuiItem::no(),"doubleCheckDelete") )
		{
		case KMessageBox::Yes: TQDialog::accept(); break;
		case KMessageBox::No: TQDialog::reject(); break;
		}
	}
	else
		TQDialog::accept();
}