Correct manual keymaps for plugins recently converted to PLA, and use manual PLA...
[maemo-rb.git] / rbutil / rbutilqt / browsedirtree.cpp
blob6c7beb9aa98e634f87f301ba31f4ef02d25cc619
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);
42 ui.tree->setLayoutDirection(Qt::LeftToRight);
46 void BrowseDirtree::setDir(const QDir &dir)
48 qDebug() << "[BrowseDirtree] setDir()" << model.index(dir.absolutePath());
50 // do not try to hilight directory if it's not valid.
51 if(!dir.exists()) return;
52 // hilight the set directory if it's valid
53 if(model.index(dir.absolutePath()).isValid()) {
54 QModelIndex p = model.index(dir.absolutePath());
55 ui.tree->setCurrentIndex(p);
56 ui.tree->expand(p);
57 ui.tree->scrollTo(p);
58 ui.tree->resizeColumnToContents(0);
62 void BrowseDirtree::setDir(const QString &dir)
64 QDir d(dir);
65 setDir(d);
68 void BrowseDirtree::setRoot(const QString &dir)
70 ui.tree->setRootIndex(model.index(dir));
73 void BrowseDirtree::setFilter(const QDir::Filters &filters)
75 model.setFilter(filters);
79 void BrowseDirtree::accept()
81 QString path;
82 path = model.filePath(ui.tree->currentIndex());
84 this->close();
85 emit itemChanged(QDir::toNativeSeparators(path));
86 setResult(QDialog::Accepted);
89 QString BrowseDirtree::getSelected()
91 QString path;
92 path = model.filePath(ui.tree->currentIndex());
93 return QDir::toNativeSeparators(path);