root/branches/audiofilebrowser/gui/src/AudioFileBrowser/AudioFileBrowser.cpp @ 480

Revision 480, 3.0 KB (checked in by wolke, 5 years ago)

tentative steps :-) browse files and return the directory

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23
24#include "AudioFileBrowser.h"
25#include "../HydrogenApp.h"
26#include "InstrumentEditor/InstrumentEditor.h"
27
28#include <hydrogen/LocalFileMng.h>
29#include <hydrogen/h2_exception.h>
30#include <hydrogen/Preferences.h>
31#include <hydrogen/hydrogen.h>
32
33#include "../widgets/Button.h"
34
35#include <QTreeWidget>
36#include <QDomDocument>
37#include <QMessageBox>
38#include <QHeaderView>
39#include <QFileDialog>
40#include <vector>
41#include <cstdlib>
42#include <iostream>
43#include <fstream>
44
45using namespace H2Core;
46using namespace std;
47
48AudioFileBrowser::AudioFileBrowser ( QWidget* pParent )
49                : QDialog ( pParent )
50                , Object ( "AudioFileBrowser" )
51{
52
53        setupUi ( this );
54        INFOLOG ( "INIT" );
55        setWindowTitle ( trUtf8 ( "Audio File Browser" ) );
56        setFixedSize ( width(), height() );
57        installEventFilter(this);
58
59
60        model = new QDirModel();
61        model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot );
62        model->setSorting(QDir::DirsFirst |QDir::Name);
63        QModelIndex index = model->index(QDir::currentPath());
64
65
66
67//      namelabel->setText(model->headerData());
68        QTreeView *tree = new QTreeView(treeView);
69        tree->setModel(model);
70        tree->resize(799, 310);
71        tree->setRootIndex(model->index(QDir::homePath()));
72
73
74
75        lastUsedDir = "";       
76        m_pselectedFile = lastUsedDir;
77
78        connect(tree, SIGNAL(clicked(const QModelIndex&)), SLOT(clicked(const QModelIndex&)));
79
80}
81
82
83AudioFileBrowser::~AudioFileBrowser()
84{
85        INFOLOG ( "DESTROY" );
86}
87
88
89void AudioFileBrowser::clicked(const QModelIndex& index)
90{
91        if ( model->isDir(index))
92                 return;
93        QString path = model->filePath(index);
94        QString message = "File: " + path;
95        namelabel->setText(message);
96        if      (
97                ( path.endsWith( ".wav" ) ) ||
98                ( path.endsWith( ".WAV" ) ) ||
99                ( path.endsWith( ".au" ) ) ||
100                ( path.endsWith( ".AU" ) ) ||
101                ( path.endsWith( ".aiff" ) ) ||
102                ( path.endsWith( ".AIFF" ) ) ||
103                ( path.endsWith( ".flac" ) ) ||
104                ( path.endsWith( ".FLAC" ) )
105                ) {
106               
107                        m_pselectedFile = path;
108                }else
109                {
110                        m_pselectedFile = "";
111                }
112}
113
114
115void AudioFileBrowser::on_cancelBTN_clicked()
116{
117        m_pselectedFile = "";
118        reject();
119}
120
121
122void AudioFileBrowser::on_openBTN_clicked()
123{
124        accept();
125}
126
127
128QString AudioFileBrowser::selectedFile()
129{
130        return m_pselectedFile;
131}
Note: See TracBrowser for help on using the browser.