summaryrefslogtreecommitdiffstats
path: root/src/part/settingsDialog.cpp
blob: 6fa88dcbbe4dd8a6292e177114a79e3c4a0fa2a8 (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
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
//Author:    Max Howell <[email protected]>, (C) 2003-4
//Copyright: See COPYING file that comes with this distribution

#include <tqapplication.h> //Getting desktop width
#include <tqcheckbox.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqslider.h>
#include <tqvbuttongroup.h>

#include <kdirselectdialog.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <knuminput.h>

#include "settingsDialog.h"
#include "Config.h"


SettingsDialog::SettingsDialog( TQWidget *parent, const char *name )
  : Dialog( parent, name, false ) //3rd param => modal
{
    colourSchemeGroup->setFrameShape( TQFrame::NoFrame );

    colourSchemeGroup->insert( new TQRadioButton( i18n("Rainbow"), colourSchemeGroup ), Filelight::Rainbow );
    colourSchemeGroup->insert( new TQRadioButton( i18n("TDE Colors"), colourSchemeGroup ), Filelight::KDE );
    colourSchemeGroup->insert( new TQRadioButton( i18n("High Contrast"), colourSchemeGroup ), Filelight::HighContrast );

    //read in settings before you make all those nasty connections!
    reset(); //makes dialog reflect global settings

    connect( &m_timer, TQT_SIGNAL(timeout()), TQT_SIGNAL(mapIsInvalid()) );

    connect( m_addButton,    TQT_SIGNAL( clicked() ), TQT_SLOT( addDirectory() ) );
    connect( m_removeButton, TQT_SIGNAL( clicked() ), TQT_SLOT( removeDirectory() ) );
    connect( m_resetButton,  TQT_SIGNAL( clicked() ), TQT_SLOT( reset() ) );
    connect( m_closeButton,  TQT_SIGNAL( clicked() ), TQT_SLOT( close() ) );

    connect( colourSchemeGroup, TQT_SIGNAL(clicked( int )), TQT_SLOT(changeScheme( int )) );
    connect( contrastSlider, TQT_SIGNAL(valueChanged( int )), TQT_SLOT(changeContrast( int )) );
    connect( contrastSlider, TQT_SIGNAL(sliderReleased()), TQT_SLOT(slotSliderReleased()) );

    connect( scanAcrossMounts,       TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( startTimer() ) );
    connect( dontScanRemoteMounts,   TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( startTimer() ) );
    connect( dontScanRemovableMedia, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( startTimer() ) );

    connect( useAntialiasing,    TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( toggleUseAntialiasing( bool ) ) );
    connect( varyLabelFontSizes, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( toggleVaryLabelFontSizes( bool ) ) );
    connect( showSmallFiles,     TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( toggleShowSmallFiles( bool ) ) );

    connect( minFontPitch, TQT_SIGNAL ( valueChanged( int ) ), TQT_SLOT( changeMinFontPitch( int ) ) );

    m_addButton->setIconSet( SmallIcon( "fileopen" ) );
    m_resetButton->setIconSet( SmallIcon( "undo" ) );
    m_closeButton->setIconSet( SmallIcon( "fileclose" ) );
}


void SettingsDialog::closeEvent( TQCloseEvent* )
{
    //if an invalidation is pending, force it now!
    if( m_timer.isActive() ) m_timer.changeInterval( 0 );

    Config::write();

    deleteLater();
}


void SettingsDialog::reset()
{
    Config::read();

    //tab 1
    scanAcrossMounts->setChecked( Config::scanAcrossMounts );
    dontScanRemoteMounts->setChecked( !Config::scanRemoteMounts );
    dontScanRemovableMedia->setChecked( !Config::scanRemovableMedia );

    dontScanRemoteMounts->setEnabled( Config::scanAcrossMounts );
    //  dontScanRemovableMedia.setEnabled( Config::scanAcrossMounts );

    m_listBox->clear();
    m_listBox->insertStringList( Config::skipList );
    m_listBox->setSelected( 0, true );

    m_removeButton->setEnabled( m_listBox->count() == 0 );

    //tab 2
    if( colourSchemeGroup->id( colourSchemeGroup->selected() ) != Config::scheme )
    {
        colourSchemeGroup->setButton( Config::scheme );
        //setButton doesn't call a single TQButtonGroup signal!
        //so we need to call this ourselves (and hence the detection above)
        changeScheme( Config::scheme );
    }
    contrastSlider->setValue( Config::contrast );

    useAntialiasing->setChecked( (Config::antiAliasFactor > 1) ? true : false );

    varyLabelFontSizes->setChecked( Config::varyLabelFontSizes );
    minFontPitch->setEnabled( Config::varyLabelFontSizes );
    minFontPitch->setValue( Config::minFontPitch );
    showSmallFiles->setChecked( Config::showSmallFiles );
}



void SettingsDialog::toggleScanAcrossMounts( bool b )
{
    Config::scanAcrossMounts = b;

    dontScanRemoteMounts->setEnabled( b );
    //dontScanRemovableMedia.setEnabled( b );
}

void SettingsDialog::toggleDontScanRemoteMounts( bool b )
{
    Config::scanRemoteMounts = !b;
}

void SettingsDialog::toggleDontScanRemovableMedia( bool b )
{
    Config::scanRemovableMedia = !b;
}



void SettingsDialog::addDirectory()
{
    const KURL url = KDirSelectDialog::selectDirectory( "/", false, this );

    //TODO error handling!
    //TODO wrong protocol handling!

    if( !url.isEmpty() )
    {
        const TQString path = url.path( 1 );

        if( !Config::skipList.contains( path ) )
        {
            Config::skipList.append( path );
            m_listBox->insertItem( path );
            m_removeButton->setEnabled( true );
        }
        else KMessageBox::sorry( this, i18n("That directory is already set to be excluded from scans") );
    }
}


void SettingsDialog::removeDirectory()
{
    Config::skipList.remove( m_listBox->currentText() ); //removes all entries that match

    //safest method to ensure consistency
    m_listBox->clear();
    m_listBox->insertStringList( Config::skipList );

    m_removeButton->setEnabled( m_listBox->count() == 0 );
}


void SettingsDialog::startTimer()
{
    m_timer.start( TIMEOUT, true );
}

void SettingsDialog::changeScheme( int s )
{
    Config::scheme = (Filelight::MapScheme)s;
    emit canvasIsDirty( 1 );
}
void SettingsDialog::changeContrast( int c )
{
    Config::contrast = c;
    emit canvasIsDirty( 3 );
}
void SettingsDialog::toggleUseAntialiasing( bool b )
{
    Config::antiAliasFactor = b ? 2 : 1;
    emit canvasIsDirty( 2 );
}
void SettingsDialog::toggleVaryLabelFontSizes( bool b )
{
    Config::varyLabelFontSizes = b;
    minFontPitch->setEnabled( b );
    emit canvasIsDirty( 0 );
}
void SettingsDialog::changeMinFontPitch( int p )
{
    Config::minFontPitch = p;
    emit canvasIsDirty( 0 );
}
void SettingsDialog::toggleShowSmallFiles( bool b )
{
    Config::showSmallFiles = b;
    emit canvasIsDirty( 1 );
}


void SettingsDialog::slotSliderReleased()
{
    emit canvasIsDirty( 2 );
}


void SettingsDialog::reject()
{
    //called when escape is pressed
    reset();
    TQDialog::reject();   //**** doesn't change back scheme so far
}

#include "settingsDialog.moc"