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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
/******************************************************************
* 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 BSCommander; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************/
/*------- include files:
-------------------------------------------------------------------*/
#include "StartDir.h"
#include "Shared.h"
#include <qlayout.h>
#include <qgroupbox.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qdir.h>
/*------- local constants:
-------------------------------------------------------------------*/
const QString StartDir::Caption = QT_TR_NOOP( "Start directory selection" );
const QString StartDir::RootDirTitle = QT_TR_NOOP( "Root directory" );
const QString StartDir::HomeDirTitle = QT_TR_NOOP( "Your home directory" );
const QString StartDir::SelectDirTitle = QT_TR_NOOP( "Select a directory" );
const QString StartDir::EditDirTitle = QT_TR_NOOP( "Type a directory" );
const QString StartDir::SelectLabel = QT_TR_NOOP( "top directory" );
//*******************************************************************
// StartDir CONSTRUCTOR
//*******************************************************************
StartDir::StartDir( QWidget* const in_parent )
: QDialog( in_parent )
, d_root_gbox ( new QGroupBox( 2, Qt::Horizontal, tr(RootDirTitle) , this ))
, d_home_gbox ( new QGroupBox( 2, Qt::Horizontal, tr(HomeDirTitle) , this ))
, d_select_gbox( new QGroupBox( 2, Qt::Horizontal, tr(SelectDirTitle), this ))
, d_edit_gbox ( new QGroupBox( 2, Qt::Horizontal, tr(EditDirTitle) , this ))
, d_root_cb ( new QCheckBox( "/", d_root_gbox ))
, d_home_cb ( new QCheckBox( QDir::homeDirPath(), d_home_gbox ))
, d_select_cb ( new QCheckBox( tr(SelectLabel), d_select_gbox ))
, d_edit_cb ( new QCheckBox( d_edit_gbox ))
, d_selector ( new QComboBox( d_select_gbox ))
, d_edit ( new QLineEdit( d_edit_gbox ))
, d_select_btn ( new QPushButton( tr(Shared::SelectBtnLabel), this ))
, d_return_btn ( new QPushButton( tr(Shared::CloseBtnLabel), this ))
, d_wait ( FALSE )
{
setCaption( tr(Caption) );
d_root_cb->setChecked( TRUE );
d_selector->setEnabled( FALSE );
d_edit->setEnabled( FALSE );
QDir dir( "/", QString::null, (QDir::Name | QDir::IgnoreCase), QDir::Dirs );
const QFileInfoList* const file_list = dir.entryInfoList();
if( file_list ) {
QFileInfoListIterator it( *file_list );
while( it.current() ) {
if( Shared::is_regular_file( it.current()->fileName() )) {
if( it.current()->isExecutable() && it.current()->isReadable() ) {
d_selector->insertItem( it.current()->fileName() );
}
}
++it;
}
}
QHBoxLayout* const main_layout = new QHBoxLayout( this );
main_layout->setMargin( Shared::LayoutMargin );
main_layout->setSpacing( Shared::LayoutSpacing );
{
QVBoxLayout* const sel_layout = new QVBoxLayout;
sel_layout->addWidget( d_root_gbox );
sel_layout->addWidget( d_home_gbox );
sel_layout->addWidget( d_select_gbox );
sel_layout->addWidget( d_edit_gbox );
main_layout->addLayout( sel_layout );
}
{
QVBoxLayout* const btn_layout = new QVBoxLayout;
btn_layout->addStretch( Shared::OverStretch );
btn_layout->addWidget( d_select_btn );
btn_layout->addWidget( d_return_btn );
main_layout->addLayout( btn_layout );
}
connect( d_root_cb , SIGNAL( toggled( bool )), this, SLOT( slot_root( bool ) ));
connect( d_home_cb , SIGNAL( toggled( bool )), this, SLOT( slot_home( bool ) ));
connect( d_select_cb , SIGNAL( toggled( bool )), this, SLOT( slot_select( bool ) ));
connect( d_edit_cb , SIGNAL( toggled( bool )), this, SLOT( slot_edit( bool ) ));
connect( d_select_btn, SIGNAL( clicked() ), this, SLOT( slot_select() ));
connect( d_return_btn, SIGNAL( clicked() ), this, SLOT( slot_return() ));
}
// end of StartDir
//*******************************************************************
// get_from_dir PUBLIC
//*******************************************************************
void StartDir::get_from_dir( QString& out_from_dir )
{
out_from_dir = QString::null;
if( d_root_cb->isChecked() ) {
out_from_dir= "/";
}
else if( d_home_cb->isChecked() ) {
out_from_dir = QDir::homeDirPath();
}
else if( d_select_cb->isChecked() ) {
out_from_dir = "/" + d_selector->currentText();
}
else if( d_edit_cb->isChecked() ) {
out_from_dir = d_edit->text();
}
}
// end of get_from_dir
//*******************************************************************
// slot_select PRIVATE slot
//*******************************************************************
void StartDir::slot_select()
{
accept();
}
// end of slot_select
//*******************************************************************
// slot_return PRIVATE slot
//*******************************************************************
void StartDir::slot_return()
{
reject();
}
// end of slot_return
//*******************************************************************
// slot_root PRIVATE slot
//*******************************************************************
void StartDir::slot_root( const bool in_is_on )
{
if( FALSE == d_wait ) {
if( in_is_on ) {
d_wait = TRUE;
deselect_all();
d_root_cb->setChecked( TRUE );
d_edit->setEnabled( FALSE );
d_selector->setEnabled( FALSE );
d_wait = FALSE;
}
}
}
// end of slot_root
//*******************************************************************
// slot_home PRIVATE slot
//*******************************************************************
void StartDir::slot_home( const bool in_is_on )
{
if( FALSE == d_wait ) {
if( in_is_on ) {
d_wait = TRUE;
deselect_all();
d_home_cb->setChecked( TRUE );
d_edit->setEnabled( FALSE );
d_selector->setEnabled( FALSE );
d_wait = FALSE;
}
}
}
// end of slot_home
//*******************************************************************
// slot_select PRIVATE slot
//*******************************************************************
void StartDir::slot_select( const bool in_is_on )
{
if( FALSE == d_wait ) {
if( in_is_on ) {
d_wait = TRUE;
deselect_all();
d_select_cb->setChecked( TRUE );
d_edit->setEnabled( FALSE );
d_selector->setEnabled( TRUE );
d_selector->setFocus();
d_wait = FALSE;
}
}
}
// end of slot_select
//*******************************************************************
// slot_edit PRIVATE slot
//*******************************************************************
void StartDir::slot_edit( const bool in_is_on )
{
if( FALSE == d_wait ) {
if( in_is_on ) {
d_wait = TRUE;
deselect_all();
d_edit_cb->setChecked( TRUE );
d_selector->setEnabled( FALSE );
d_edit->setEnabled( TRUE );
d_edit->setFocus();
d_wait = FALSE;
}
}
}
// end of slot_select
//*******************************************************************
// deselect_all PRIVATE
//*******************************************************************
void StartDir::deselect_all()
{
d_root_cb->setChecked( FALSE );
d_home_cb->setChecked( FALSE );
d_select_cb->setChecked( FALSE );
d_edit_cb->setChecked( FALSE );
}
// end of deselct_all
|