1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "browsedirtree.h"
23 #include "ui_browsedirtreefrm.h"
26 BrowseDirtree::BrowseDirtree(QWidget
*parent
, const QString
&caption
) : QDialog(parent
)
30 ui
.tree
->setModel(&model
);
31 model
.setReadOnly(true);
32 model
.setSorting(QDir::Name
| QDir::DirsFirst
| QDir::IgnoreCase
);
35 setWindowTitle(caption
);
37 // disable size / date / type columns
38 ui
.tree
->setColumnHidden(1, true);
39 ui
.tree
->setColumnHidden(2, true);
40 ui
.tree
->setColumnHidden(3, true);
41 ui
.tree
->setAlternatingRowColors(true);
45 void BrowseDirtree::setDir(const QDir
&dir
)
47 qDebug() << "BrowseDirtree::setDir()" << model
.index(dir
.absolutePath());
49 // do not try to hilight directory if it's not valid.
50 if(!dir
.exists()) return;
51 // hilight the set directory if it's valid
52 if(model
.index(dir
.absolutePath()).isValid()) {
53 QModelIndex p
= model
.index(dir
.absolutePath());
54 ui
.tree
->setCurrentIndex(p
);
57 ui
.tree
->resizeColumnToContents(0);
61 void BrowseDirtree::setDir(const QString
&dir
)
67 void BrowseDirtree::setRoot(const QString
&dir
)
69 ui
.tree
->setRootIndex(model
.index(dir
));
72 void BrowseDirtree::setFilter(const QDir::Filters
&filters
)
74 model
.setFilter(filters
);
78 void BrowseDirtree::accept()
81 path
= model
.filePath(ui
.tree
->currentIndex());
84 emit
itemChanged(QDir::toNativeSeparators(path
));
85 setResult(QDialog::Accepted
);
88 QString
BrowseDirtree::getSelected()
91 path
= model
.filePath(ui
.tree
->currentIndex());
92 return QDir::toNativeSeparators(path
);