Mercurial > hg > easaier-soundaccess
diff widgets/BrowseLineEdit.cpp @ 228:a6b881972a62
add FileProperty to browse file on local system for query by humming
author | lbajardsilogic |
---|---|
date | Fri, 29 Feb 2008 11:08:09 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/BrowseLineEdit.cpp Fri Feb 29 11:08:09 2008 +0000 @@ -0,0 +1,63 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* Sound Access + EASAIER client application. + Silogic 2007. Laure Bajard. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include <QFileDialog> +#include <QMessageBox> +#include <QHBoxLayout> + +#include "BrowseLineEdit.h" + +BrowseLineEdit::BrowseLineEdit(void) : QWidget() +{ + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->setSpacing(0); + mainLayout->setMargin(0); + + m_lineEdit = new QLineEdit(); + m_browseButton = new QPushButton(tr("&Browse...")); + + connect(m_lineEdit, SIGNAL(textChanged(const QString &)), this, SIGNAL(textChanged(const QString &))); + + connect(m_browseButton, SIGNAL(clicked()), this, SLOT(browse())); + + mainLayout->addWidget(m_lineEdit); + mainLayout->addSpacing(10); + mainLayout->addWidget(m_browseButton); + + setLayout(mainLayout); + +} + +BrowseLineEdit::~BrowseLineEdit(void) +{ +} + +void BrowseLineEdit::browse() +{ + QString curPath = m_lineEdit->text(); + + QString path = QFileDialog::getOpenFileName(this, tr("Select file"), curPath); + + if (path.isEmpty()) return; + + if (!(QFileInfo(path).exists() && + QFileInfo(path).isFile() && + QFileInfo(path).isReadable())) + { + QMessageBox::critical(this, tr("Failed to open file"), tr("File \"%1\" does not exist or is not a readable file").arg(path)); + return; + } + + m_lineEdit->setText(path); + +} \ No newline at end of file