rbutil: limit the mountpoint selection to /Media on linux and /Volumes on Mac.
[kugel-rb.git] / rbutil / rbutilqt / browsedirtree.cpp
blob2eabe7556449938226079669f23f8078ee18819c
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) : 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 // disable size / date / type columns
35 ui.tree->setColumnHidden(1, true);
36 ui.tree->setColumnHidden(2, true);
37 ui.tree->setColumnHidden(3, true);
38 ui.tree->setAlternatingRowColors(true);
42 void BrowseDirtree::setDir(QDir &dir)
44 qDebug() << "BrowseDirtree::setDir()" << model.index(dir.absolutePath());
46 // do not try to hilight directory if it's not valid.
47 if(!dir.exists()) return;
48 // hilight the set directory if it's valid
49 if(model.index(dir.absolutePath()).isValid()) {
50 QModelIndex p = model.index(dir.absolutePath());
51 ui.tree->setCurrentIndex(p);
52 ui.tree->scrollTo(p);
53 ui.tree->resizeColumnToContents(0);
57 void BrowseDirtree::setRoot(QString dir)
59 ui.tree->setRootIndex(model.index(dir));
62 void BrowseDirtree::setFilter(QDir::Filters filters)
64 model.setFilter(filters);
68 void BrowseDirtree::accept()
70 QString path;
71 path = model.filePath(ui.tree->currentIndex());
73 this->close();
74 emit itemChanged(QDir::toNativeSeparators(path));
75 setResult(QDialog::Accepted);
78 QString BrowseDirtree::getSelected()
80 QString path;
81 path = model.filePath(ui.tree->currentIndex());
82 return QDir::toNativeSeparators(path);