summaryrefslogtreecommitdiffstats
path: root/src/dirdialog.cpp
blob: b76d14860b0ae3ffd1ca97ca75491f114e348ad9 (plain)
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

#include "dirdialog.h"
#include "config.h"

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqdir.h>
#include <tqcheckbox.h>

#include <klocale.h>
#include <kiconloader.h>
#include <klineedit.h>
#include <kpushbutton.h>
// #include <kurlrequester.h>
#include <klistbox.h>
#include <kfiledialog.h>

DirDialog::DirDialog( Config* config, Mode mode, TQWidget *parent, const char *name, bool modal, WFlags f )
    : KDialog( parent, name, modal, f )
{
    // create an icon loader object for loading icons
    KIconLoader* iconLoader = new KIconLoader();

    setCaption( i18n("Add folder") );
    resize( 400, 235 );
    setIcon( iconLoader->loadIcon("folder_open",KIcon::Small) );

    TQGridLayout* grid = new TQGridLayout( this, 4, 1, 11, 6 );

    TQHBoxLayout* directoryBox = new TQHBoxLayout();
    grid->addLayout( directoryBox, 0, 0 );

    TQLabel* labelDirectory = new TQLabel( i18n("Directory:"), this, "labelDirectory" );
    directoryBox->addWidget( labelDirectory );

//     uDirectory = new KURLRequester( this, "uDirectory" );
//     uDirectory->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
//     uDirectory->setURL( TQDir::homeDirPath() );
//     directoryBox->addWidget( uDirectory );

    lDirectory = new KLineEdit( this, "lDirectory" );
    directoryBox->addWidget( lDirectory );

    pDirectory = new KPushButton( iconLoader->loadIcon("folder_open",KIcon::Small), "", this, "pDirectory" );
    directoryBox->addWidget( pDirectory );
    connect( pDirectory, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(selectDirectoryClicked())
             );

    TQHBoxLayout* fileTypesBox = new TQHBoxLayout();
    grid->addLayout( fileTypesBox, 1, 0 );

    fileTypes = new KListBox( this, "fileTypes" );
    if( mode == Convert ) fileTypes->insertStringList( config->fileTypes() );
    else if( mode == ReplayGain ) fileTypes->insertStringList( config->replayGainFileTypes() );
    fileTypes->setSelectionMode( TQListBox::Multi );
    for( int i = 0; i < fileTypes->count(); i++ ) fileTypes->setSelected( i, true );
    fileTypesBox->addWidget( fileTypes );

    TQVBoxLayout* fileTypesButtonsBox = new TQVBoxLayout();
    fileTypesBox->addLayout( fileTypesButtonsBox );

    pSelectAll = new KPushButton( iconLoader->loadIcon("font",KIcon::Small), i18n("Select all"), this, "pSelectAll" );
    fileTypesButtonsBox->addWidget( pSelectAll );
    connect( pSelectAll, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(selectAllClicked())
             );

    pSelectNone = new KPushButton( iconLoader->loadIcon("empty",KIcon::Small), i18n("Select none"), this, "pSelectNone" );
    fileTypesButtonsBox->addWidget( pSelectNone );
    connect( pSelectNone, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(selectNoneClicked())
             );

    cRecursive = new TQCheckBox( i18n("Recursive"), this, "cRecursive" );
    cRecursive->setChecked( true );
    recursive = true;
    fileTypesButtonsBox->addWidget( cRecursive );
    connect( cRecursive, TQT_SIGNAL(toggled(bool)),
             this, TQT_SLOT(recursiveToggled(bool))
           );

    fileTypesButtonsBox->addStretch();

    TQHBoxLayout* buttonBox = new TQHBoxLayout();
    grid->addLayout( buttonBox, 2, 0 );

    pOk = new KPushButton( iconLoader->loadIcon("folder_open",KIcon::Small), i18n("Open"), this, "pOk" );
    buttonBox->addWidget( pOk );
    connect( pOk, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(okClicked())
             );

    buttonBox->addStretch();

    pCancel = new KPushButton( iconLoader->loadIcon("cancel",KIcon::Small),i18n("Cancel"), this, "pCancel" );
    pOk->setFocus();
    buttonBox->addWidget( pCancel );
    connect( pCancel, TQT_SIGNAL(clicked()),
               this, TQT_SLOT(reject())
             );

    // delete the icon loader object
    delete iconLoader;

    TQString directory = KFileDialog::getExistingDirectory( ":file_open", this, i18n("Choose a directory") );
    if( !directory.isEmpty() )
    {
        lDirectory->setText( directory );
    }
    else
    {
        lDirectory->setText( TQDir::homeDirPath() );
    }
}

DirDialog::~DirDialog()
{}

void DirDialog::okClicked()
{
    selectedFileTypes.clear();
    for( int i = 0; i < fileTypes->count(); i++ ) {
        if( fileTypes->isSelected(i) ) selectedFileTypes += TQStringList::split(", ",fileTypes->text(i));
    }
    directory = lDirectory->text();

    emit accept();
}

void DirDialog::selectDirectoryClicked()
{
    TQString directory = KFileDialog::getExistingDirectory( lDirectory->text(), this, i18n("Choose a directory") );
    if( !directory.isEmpty() )
    {
        lDirectory->setText( directory );
    }
}

void DirDialog::selectAllClicked()
{
    for( int i = 0; i < fileTypes->count(); i++ ) fileTypes->setSelected( i, true );
}

void DirDialog::selectNoneClicked()
{
    for( int i = 0; i < fileTypes->count(); i++ ) fileTypes->setSelected( i, false );
}

void DirDialog::recursiveToggled( bool checked )
{
    recursive = checked;
}