File: kdirselectdialog.cpp

package info (click to toggle)
kdeutils 4%3A2.2.2-9.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,892 kB
  • ctags: 10,879
  • sloc: cpp: 82,942; sh: 11,754; ansic: 4,638; perl: 1,852; makefile: 706; python: 258
file content (101 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download
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
/*
	Copyright (C) 2001 Michael Jarrett <michaelj@corel.com>

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License version 2 as published by the Free Software Foundation.

	This library 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.

	You should have received a copy of the GNU Library General Public License
	along with this library; see the file COPYING.LIB.  If not, write to
	the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
	Boston, MA 02111-1307, USA.
*/

#include <qwidget.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <kdialog.h>
#include <kurl.h>
#include <klocale.h>

#include "kdirselect.h"
#include "kdirselectdialog.h"

/**
* The constructor. Nothing out of the ordinary here.
*/
KDirSelectDialog::KDirSelectDialog(KURL &rootURL,
	QWidget *parent, const char *name) : KDialog(parent, name, true)
{
	setCaption(i18n("Directories"));

	// Create buttons
	QPushButton *okButton = new QPushButton(i18n("&OK"), this);
	QPushButton *cancelButton = new QPushButton(i18n("&Cancel"), this);
	okButton->setDefault(true);

	connect(okButton, SIGNAL(pressed()), this, SLOT(accept()));
	connect(cancelButton, SIGNAL(pressed()), this, SLOT(reject()));

	// Create dir list
	m_dirList = new KDirSelect(rootURL, this);

	// Setup layouts
	m_mainLayout = new QVBoxLayout(this, marginHint(), spacingHint());
	m_mainLayout->addWidget(m_dirList, 1);
	
	m_buttonLayout = new QHBoxLayout(spacingHint());
	m_mainLayout->addLayout(m_buttonLayout);
	m_buttonLayout->addStretch(1);
	
	m_buttonLayout->addWidget(cancelButton);
	m_buttonLayout->addWidget(okButton);
}


/**
* Deletes the layouts used in the dialog.
*/
KDirSelectDialog::~KDirSelectDialog()
{
	// Deletes layout, which will delete child layouts
	// The buttons will be killed by QWidget.
	hide();
	delete m_buttonLayout; m_buttonLayout = 0;
	delete m_mainLayout; 	m_mainLayout = 0;
}


/**
* Returns the currently-selected URL, or a blank URL if none is selected.
* @return The currently-selected URL, if one was selected.
*/
KURL KDirSelectDialog::getURL()
{
	return m_dirList->getSelectedURL();
}


/**
* Creates a KDirSelectDialog, and returns the result.
* @param root The root from which to start enumerating directories.
* The tree will display this directory and subdirectories of it.
* @return The URL selected, or an empty URL if the user cancelled
* or no URL was selected.
*/
KURL KDirSelectDialog::selectDirectory(KURL root, QWidget *parent)
{
	KDirSelectDialog myDialog(root, parent, "kdirselectdialog");
	if(myDialog.exec())
		return myDialog.getURL();
	else
		return KURL();
}


#include "kdirselectdialog.moc"