Introduce Rockbox Utility to the manual as automated installation option. Only rather...
[Rockbox.git] / rbutil / rbutilqt / browsedirtree.cpp
blobc2441f27cdc750745ec21b0d96bf924be1bf98ab
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
20 #include <QtGui>
22 #include "browsedirtree.h"
23 #include "ui_browsedirtreefrm.h"
26 BrowseDirtree::BrowseDirtree(QWidget *parent, const QString &caption) : QDialog(parent)
28 ui.setupUi(this);
29 this->setModal(true);
30 ui.tree->setModel(&model);
31 model.setReadOnly(true);
32 model.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase);
34 if(caption!="")
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);
55 ui.tree->expand(p);
56 ui.tree->scrollTo(p);
57 ui.tree->resizeColumnToContents(0);
61 void BrowseDirtree::setDir(const QString &dir)
63 QDir d(dir);
64 setDir(d);
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()
80 QString path;
81 path = model.filePath(ui.tree->currentIndex());
83 this->close();
84 emit itemChanged(QDir::toNativeSeparators(path));
85 setResult(QDialog::Accepted);
88 QString BrowseDirtree::getSelected()
90 QString path;
91 path = model.filePath(ui.tree->currentIndex());
92 return QDir::toNativeSeparators(path);