1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/******************************************************************
* Copyright (C) 2005, 2006 Piotr Pszczolkowski
*-------------------------------------------------------------------
* This file is part of BSCommander (Beesoft Commander).
*
* BsC 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.
*
* BsC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BsC; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************/
#ifndef INCLUDED_TREE_H
#define INCLUDED_TREE_H
/*------- include files:
-------------------------------------------------------------------*/
#ifndef INCLUDED_QDIALOG_H
#include <qdialog.h>
#define INCLUDED_QDIALOG_H
#endif // INCLUDED_QDIALOG_H
#ifndef INCLUDED_QFILEINFO_H
#include <qfileinfo.h>
#define INCLUDED_QFILEINFO_H
#endif // INCLUDED_QFILEINFO_H
#ifndef INCLUDED_QLISTVIEW_H
#include <qlistview.h>
#define INCLUDED_QLISTVIEW_H
#endif // INCLUDED_QLISTVIEW_H
#ifndef INCLUDED_QPIXMAP_H
#include <qpixmap.h>
#define INCLUDED_QPIXMAP_H
#endif // INCLUDED_QPIXMAP_H
/*------- forward declarations:
-------------------------------------------------------------------*/
class QListView;
class QListViewItem;
class QPushButton;
class QLabel;
/*------- class declaration:
-------------------------------------------------------------------*/
class Tree : public QDialog
{
Q_OBJECT
// ******* CONSTRUCTION *******
public:
Tree( QWidget*, const QString& = QString::null );
private:
Tree( const Tree& );
Tree& operator=( const Tree& );
// ******* TYPES *******
private:
class ViewItem : public QListViewItem
{
public:
ViewItem( QListView* const in_parent, const QFileInfo* const in_finfo )
: QListViewItem( in_parent, ( "/" == in_finfo->absFilePath() ) ? "/" : in_finfo->fileName() )
, d_info( *in_finfo )
{
add_icon();
}
ViewItem( ViewItem* const in_parent, const QFileInfo* const in_finfo )
: QListViewItem( in_parent, in_finfo->fileName() )
, d_info( *in_finfo )
{
add_icon();
}
private:
ViewItem( const ViewItem& );
ViewItem& operator=( const ViewItem& );
public:
const QFileInfo d_info;
private:
void add_icon();
};
// ******* CONSTANTS *******
private:
static const QString Caption;
static const QString Dirs;
static const QString CantReadDir;
static const QString DirNotValid;
static const QString DirNotFound;
// ******* MEMBERS *******
private:
QString d_from_dir;
const QString d_current_dir;
QListView* const d_view;
QPushButton* const d_select_btn;
QPushButton* const d_return_btn;
bool d_break;
bool d_finished;
QFileInfo d_finfo;
QLabel* const d_counter_lb;
int d_counter;
// ******* METHODS *******
private:
void show ();
void polish();
void keyPressEvent( QKeyEvent* e );
void parse( ViewItem*, const QString&, const int );
void select();
void update_counter();
public:
QString get_dir();
private slots:
void slot_select();
void slot_return();
};
//*******************************************************************
// add_icon PRIVATE inline
//*******************************************************************
inline void Tree::ViewItem::add_icon()
{
if( d_info.isExecutable() && d_info.isReadable() ) {
setPixmap( 0, QPixmap::fromMimeSource( "folder.png" ));
}
else {
setPixmap( 0, QPixmap::fromMimeSource( "ifolder.png" ));
}
}
// end of add_icon
//*******************************************************************
// get_dir PRIVATE inline
//*******************************************************************
inline QString Tree::get_dir()
{
const ViewItem* const item = dynamic_cast<ViewItem*>( d_view->selectedItem() );
if( item ) return item->d_info.absFilePath();
else return QString::null;
}
// end of get_dir
#endif // INCLUDED_TREE_H
|