By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release. View | Details | Raw Unified | Return to bug 1923
Collapse All | Expand All

(-)tdebase/konqueror/konq_mainwindow.cc (-1 / +2 lines)
Lines 3881-3887 Link Here
3881
      "tde-kcmhistory.desktop" << "tde-cookies.desktop" <<
3881
      "tde-kcmhistory.desktop" << "tde-cookies.desktop" <<
3882
      "tde-cache.desktop" << "tde-proxy.desktop" << "tde-kcmcss.desktop" <<
3882
      "tde-cache.desktop" << "tde-proxy.desktop" << "tde-kcmcss.desktop" <<
3883
      "tde-kcmcgi.desktop" << "tde-crypto.desktop" << "tde-useragent.desktop" <<
3883
      "tde-kcmcgi.desktop" << "tde-crypto.desktop" << "tde-useragent.desktop" <<
3884
      "tde-tdehtml_plugins.desktop" << "kde-kcmkonqyperformance.desktop";
3884
      "tde-tdehtml_plugins.desktop" << "kde-kcmkonqyperformance.desktop" <<
3885
      "kde-ktrashpropsdlgplugin.desktop";
3885
3886
3886
3887
3887
  if (!kapp->authorizeControlModules(configModules()).isEmpty())
3888
  if (!kapp->authorizeControlModules(configModules()).isEmpty())
(-)tdebase/tdeioslave/trash/CMakeLists.txt (-4 / +4 lines)
Lines 25-31 Link Here
25
25
26
##### other data ################################
26
##### other data ################################
27
27
28
install( FILES trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
28
install( FILES ktrashpropsdlgplugin.desktop trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
29
29
30
30
31
##### trashcommon (static) ######################
31
##### trashcommon (static) ######################
Lines 33-39 Link Here
33
set( target trashcommon )
33
set( target trashcommon )
34
34
35
tde_add_library( ${target} STATIC_PIC AUTOMOC
35
tde_add_library( ${target} STATIC_PIC AUTOMOC
36
  SOURCES trashimpl.cpp
36
  SOURCES trashimpl.cpp discspaceutil.cpp
37
)
37
)
38
38
39
39
Lines 42-48 Link Here
42
set( target tdeio_trash )
42
set( target tdeio_trash )
43
43
44
tde_add_kpart( ${target} AUTOMOC
44
tde_add_kpart( ${target} AUTOMOC
45
  SOURCES tdeio_trash.cpp
45
  SOURCES tdeio_trash.cpp ktrashpropsdlgplugin.cpp
46
  LINK trashcommon-static tdeio-shared
46
  LINK trashcommon-static tdeio-shared
47
  DESTINATION ${PLUGIN_INSTALL_DIR}
47
  DESTINATION ${PLUGIN_INSTALL_DIR}
48
)
48
)
Lines 53-59 Link Here
53
set( target ktrash )
53
set( target ktrash )
54
54
55
tde_add_executable( ${target}
55
tde_add_executable( ${target}
56
  SOURCES ktrash.cpp
56
  SOURCES discspaceutil.cpp ktrash.cpp ktrashpropsdlgplugin.cpp
57
  LINK tdeio-shared
57
  LINK tdeio-shared
58
  DESTINATION ${BIN_INSTALL_DIR}
58
  DESTINATION ${BIN_INSTALL_DIR}
59
)
59
)
(-)tdebase/tdeioslave/trash/Makefile.am (-2 / +11 lines)
Lines 3-9 Link Here
3
3
4
SUBDIRS = . tdefile-plugin
4
SUBDIRS = . tdefile-plugin
5
5
6
kde_module_LTLIBRARIES = tdeio_trash.la
6
kde_module_LTLIBRARIES = tdeio_trash.la ktrashpropsdlgplugin.la
7
7
8
tdeio_trash_la_SOURCES = tdeio_trash.cpp
8
tdeio_trash_la_SOURCES = tdeio_trash.cpp
9
tdeio_trash_la_LIBADD  = libtrashcommon.la $(LIB_TDEIO)
9
tdeio_trash_la_LIBADD  = libtrashcommon.la $(LIB_TDEIO)
Lines 17-23 Link Here
17
kde_services_DATA = trash.protocol
17
kde_services_DATA = trash.protocol
18
18
19
noinst_LTLIBRARIES = libtrashcommon.la
19
noinst_LTLIBRARIES = libtrashcommon.la
20
libtrashcommon_la_SOURCES = trashimpl.cpp
20
libtrashcommon_la_SOURCES = trashimpl.cpp discspaceutil.cpp
21
21
22
check_PROGRAMS = testtrash
22
check_PROGRAMS = testtrash
23
testtrash_SOURCES = testtrash.cpp
23
testtrash_SOURCES = testtrash.cpp
Lines 29-31 Link Here
29
messages:
29
messages:
30
	$(XGETTEXT) `find . -name "*.cc" -o -name "*.cpp" -o -name "*.h"` -o $(podir)/tdeio_trash.pot
30
	$(XGETTEXT) `find . -name "*.cc" -o -name "*.cpp" -o -name "*.h"` -o $(podir)/tdeio_trash.pot
31
31
32
# ktrashpropsdlgplugin target
33
noinst_HEADERS = ktrashpropsdlgplugin.h discspaceutil.h
34
35
ktrashpropsdlgplugin_la_SOURCES = ktrashpropsdlgplugin.cpp discspaceutil.cpp trashimpl.cpp
36
ktrashpropsdlgplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
37
ktrashpropsdlgplugin_la_LIBADD = $(LIB_TDEIO)
38
39
services_DATA = ktrashpropsdlgplugin.desktop
40
servicesdir = $(kde_servicesdir)
(-)tdebase/tdeioslave/trash/discspaceutil.cpp (+112 lines)
Line 0 Link Here
1
/*
2
   This file is part of the KDE project
3
4
   Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
5
6
   This library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Library General Public
8
   License as published by the Free Software Foundation; either
9
   version 2 of the License, or (at your option) any later version.
10
11
   This library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Library General Public License for more details.
15
16
   You should have received a copy of the GNU Library General Public License
17
   along with this library; see the file COPYING.LIB.  If not, write to
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
   Boston, MA 02110-1301, USA.
20
*/
21
22
#include <tqapplication.h>
23
#include <tqdir.h>
24
#include <tqeventloop.h>
25
#include <tqfileinfo.h>
26
27
#include <kdiskfreesp.h>
28
#include <kdebug.h>
29
30
#include "discspaceutil.h"
31
32
DiscSpaceUtil::DiscSpaceUtil( const TQString &directory, TQObject *parent )
33
  : TQObject( parent ),
34
    mDirectory( directory ),
35
    mFullSize( 0 )
36
{
37
  calculateFullSize();
38
}
39
40
unsigned long DiscSpaceUtil::sizeOfPath( const TQString &path )
41
{
42
  TQFileInfo info( path );
43
  if ( !info.exists() ) {
44
    return 0;
45
  }
46
47
  if ( info.isFile() ) {
48
    return info.size();
49
  } else if ( info.isDir() ) {
50
    TQDir dir( path );
51
    const TQFileInfoList *infos = dir.entryInfoList( TQDir::Files | TQDir::Dirs | TQDir::NoSymLinks );
52
    TQFileInfoListIterator it( *infos );
53
54
    unsigned long sum = 0;
55
    TQFileInfo *info = 0;
56
    while ( (info = it.current()) != 0 ) {
57
      if ( info->fileName() != "." && info->fileName() != ".." )
58
      sum += sizeOfPath( info->absFilePath() );
59
      ++it;
60
    }
61
62
    return sum;
63
  } else {
64
    return 0;
65
  }
66
}
67
68
double DiscSpaceUtil::usage( unsigned long additional ) const
69
{
70
  if ( mFullSize == 0 )
71
    return 0;
72
73
  unsigned long sum = sizeOfPath( mDirectory );
74
  sum += additional;
75
76
  sum = sum/1024; // convert to kB
77
78
  return (((double)sum*100)/(double)mFullSize);
79
}
80
81
unsigned long DiscSpaceUtil::size() const
82
{
83
  return mFullSize;
84
}
85
86
TQString DiscSpaceUtil::mountPoint() const
87
{
88
  return mMountPoint;
89
}
90
91
void DiscSpaceUtil::foundMountPoint( const TQString &mountPoint, unsigned long kbSize, unsigned long, unsigned long )
92
{
93
  mFullSize = kbSize;
94
  mMountPoint = mountPoint;
95
}
96
97
void DiscSpaceUtil::done()
98
{
99
  tqApp->eventLoop()->exitLoop();
100
}
101
102
void DiscSpaceUtil::calculateFullSize()
103
{
104
  KDiskFreeSp *sp = KDiskFreeSp::findUsageInfo( mDirectory );
105
  connect( sp, SIGNAL( foundMountPoint( const TQString&, unsigned long, unsigned long, unsigned long ) ),
106
           this, SLOT( foundMountPoint( const TQString&, unsigned long, unsigned long, unsigned long ) ) );
107
  connect( sp, SIGNAL( done() ), this, SLOT( done() ) );
108
109
  tqApp->eventLoop()->enterLoop();
110
}
111
112
#include "discspaceutil.moc"
(-)tdebase/tdeioslave/trash/discspaceutil.h (+81 lines)
Line 0 Link Here
1
/*
2
   This file is part of the KDE project
3
4
   Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
5
6
   This library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Library General Public
8
   License as published by the Free Software Foundation; either
9
   version 2 of the License, or (at your option) any later version.
10
11
   This library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Library General Public License for more details.
15
16
   You should have received a copy of the GNU Library General Public License
17
   along with this library; see the file COPYING.LIB.  If not, write to
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
   Boston, MA 02110-1301, USA.
20
*/
21
22
#ifndef DISCSPACEUTIL_H
23
#define DISCSPACEUTIL_H
24
25
#include <tqobject.h>
26
#include <tqstring.h>
27
28
/**
29
 * A small utility class to access and calculate
30
 * size and usage of mount points.
31
 */
32
class DiscSpaceUtil : public QObject
33
{
34
  Q_OBJECT
35
36
  public:
37
    /**
38
     * Creates a new disc space util.
39
     *
40
     * @param directory A directory the util shall work on.
41
     * @param parent The parent object.
42
     */
43
    explicit DiscSpaceUtil( const TQString &directory, TQObject *parent = 0 );
44
45
    /**
46
     * Returns the usage of the directory pass in the constructor on this
47
     * mount point in percent.
48
     *
49
     * @param additional An additional amount of bytes that is added to the
50
     *                   directory size before the usage is calculated.
51
     */
52
    double usage( unsigned long additional = 0 ) const;
53
54
    /**
55
     * Returns the size of the partition in kilo bytes.
56
     */
57
    unsigned long size() const;
58
59
    /**
60
     * Returns the mount point of the directory.
61
     */
62
    TQString mountPoint() const;
63
64
    /**
65
     * Returns the size of the given path in bytes.
66
     */
67
    static unsigned long sizeOfPath( const TQString &path );
68
69
  private slots:
70
    void foundMountPoint( const TQString&, unsigned long, unsigned long, unsigned long );
71
    void done();
72
73
  private:
74
    void calculateFullSize();
75
76
    TQString mDirectory;
77
    unsigned long mFullSize;
78
    TQString mMountPoint;
79
};
80
81
#endif
(-)tdebase/tdeioslave/trash/ktrashpropsdlgplugin.cpp (+287 lines)
Line 0 Link Here
1
/*
2
   This file is part of the KDE project
3
4
   Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
5
6
   This library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Library General Public
8
   License as published by the Free Software Foundation; either
9
   version 2 of the License, or (at your option) any later version.
10
11
   This library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Library General Public License for more details.
15
16
   You should have received a copy of the GNU Library General Public License
17
   along with this library; see the file COPYING.LIB.  If not, write to
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
   Boston, MA 02110-1301, USA.
20
*/
21
22
#include "ktrashpropsdlgplugin.h"
23
#include "discspaceutil.h"
24
#include "trashimpl.h"
25
26
#include <tqcheckbox.h>
27
#include <tqcombobox.h>
28
#include <tqlabel.h>
29
#include <tqlayout.h>
30
#include <tqlistbox.h>
31
#include <tqspinbox.h>
32
33
#include <kdesktopfile.h>
34
#include <kgenericfactory.h>
35
#include <tdeglobal.h>
36
#include <kiconloader.h>
37
#include <tdelocale.h>
38
#include <knuminput.h>
39
40
typedef KGenericFactory<KTrashPropsDlgPlugin, KPropertiesDialog> Factory;
41
K_EXPORT_COMPONENT_FACTORY( ktrashpropsdlgplugin, Factory( "ktrashpropsdlgplugin" ) )
42
43
KTrashPropsDlgPlugin::KTrashPropsDlgPlugin( KPropertiesDialog *dialog, const char*, const TQStringList& )
44
  : KPropsDlgPlugin( dialog )
45
{
46
  if ( dialog->items().count() != 1 )
47
    return;
48
49
  KFileItem *item = dialog->items().first();
50
51
  if ( !KPropsDlgPlugin::isDesktopFile( item ) )
52
    return;
53
54
  KDesktopFile deskFile( item->url().path(), true /* readonly */ );
55
56
  if ( deskFile.readURL() != "trash:/" )
57
    return;
58
59
  TDEGlobal::locale()->insertCatalogue( "tdeio_trash" );
60
61
  mTrashImpl = new TrashImpl();
62
  mTrashImpl->init();
63
64
  readConfig();
65
66
  TQFrame *frame = dialog->addPage( i18n( "Size Limits" ) );
67
  setupGui( frame );
68
69
  useTypeChanged();
70
71
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
72
           this, SLOT( setDirty() ) );
73
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
74
           this, SLOT( useTypeChanged() ) );
75
  connect( mDays, SIGNAL( valueChanged( int ) ),
76
           this, SLOT( setDirty() ) );
77
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
78
           this, SLOT( setDirty() ) );
79
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
80
           this, SLOT( useTypeChanged() ) );
81
  connect( mPercent, SIGNAL( valueChanged( double ) ),
82
           this, SLOT( percentChanged( double ) ) );
83
  connect( mPercent, SIGNAL( valueChanged( double ) ),
84
           this, SLOT( setDirty() ) );
85
  connect( mLimitReachedAction, SIGNAL( activated( int ) ),
86
           this, SLOT( setDirty() ) );
87
88
  trashChanged( 0 );
89
}
90
91
KTrashPropsDlgPlugin::~KTrashPropsDlgPlugin()
92
{
93
}
94
95
void KTrashPropsDlgPlugin::applyChanges()
96
{
97
  if ( !mCurrentTrash.isEmpty() ) {
98
    ConfigEntry entry;
99
    entry.useTimeLimit = mUseTimeLimit->isChecked();
100
    entry.days = mDays->value();
101
    entry.useSizeLimit = mUseSizeLimit->isChecked();
102
    entry.percent = mPercent->value(),
103
    entry.actionType = mLimitReachedAction->currentItem();
104
    mConfigMap.insert( mCurrentTrash, entry );
105
  }
106
107
  writeConfig();
108
}
109
110
void KTrashPropsDlgPlugin::percentChanged( double percent )
111
{
112
  DiscSpaceUtil util( mCurrentTrash );
113
114
  double partitionSize = util.size() * 1024.0; // convert to byte
115
116
  double size = partitionSize*(percent/100.0);
117
118
  TQString unit = i18n( "Byte" );
119
  if ( size > 1024 ) {
120
    unit = i18n( "KByte" );
121
    size = size/1024.0;
122
  }
123
  if ( size > 1024 ) {
124
    unit = i18n( "MByte" );
125
    size = size/1024.0;
126
  }
127
  if ( size > 1024 ) {
128
    unit = i18n( "GByte" );
129
    size = size/1024.0;
130
  }
131
  if ( size > 1024 ) {
132
    unit = i18n( "TByte" );
133
    size = size/1024.0;
134
  }
135
136
  mSizeLabel->setText( i18n( "(%1 %2)" ).arg( TQString::number( size, 'f', 2 ) ).arg( unit ) );
137
}
138
139
void KTrashPropsDlgPlugin::trashChanged( int value )
140
{
141
  const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
142
143
  if ( !mCurrentTrash.isEmpty() ) {
144
    ConfigEntry entry;
145
    entry.useTimeLimit = mUseTimeLimit->isChecked();
146
    entry.days = mDays->value();
147
    entry.useSizeLimit = mUseSizeLimit->isChecked();
148
    entry.percent = mPercent->value(),
149
    entry.actionType = mLimitReachedAction->currentItem();
150
    mConfigMap.insert( mCurrentTrash, entry );
151
  }
152
153
  mCurrentTrash = map[ value ];
154
155
  if ( mConfigMap.contains( mCurrentTrash ) ) {
156
    const ConfigEntry entry = mConfigMap[ mCurrentTrash ];
157
    mUseTimeLimit->setChecked( entry.useTimeLimit );
158
    mDays->setValue( entry.days );
159
    mUseSizeLimit->setChecked( entry.useSizeLimit );
160
    mPercent->setValue( entry.percent );
161
    mLimitReachedAction->setCurrentItem( entry.actionType );
162
  } else {
163
    mUseTimeLimit->setChecked( false );
164
    mDays->setValue( 7 );
165
    mUseSizeLimit->setChecked( true );
166
    mPercent->setValue( 10.0 );
167
    mLimitReachedAction->setCurrentItem( 0 );
168
  }
169
170
  percentChanged( mPercent->value() );
171
}
172
173
void KTrashPropsDlgPlugin::useTypeChanged()
174
{
175
  mDays->setEnabled( mUseTimeLimit->isChecked() );
176
  mSizeWidget->setEnabled( mUseSizeLimit->isChecked() );
177
}
178
179
void KTrashPropsDlgPlugin::readConfig()
180
{
181
  TDEConfig config( "ktrashrc" );
182
  mConfigMap.clear();
183
184
  const TQStringList groups = config.groupList();
185
  for ( uint i = 0; i < groups.count(); ++i ) {
186
    if ( groups[ i ].startsWith( "/" ) ) {
187
      config.setGroup( groups[ i ] );
188
      ConfigEntry entry;
189
      entry.useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
190
      entry.days = config.readNumEntry( "Days", 7 );
191
      entry.useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
192
      entry.percent = config.readDoubleNumEntry( "Percent", 10 );
193
      entry.actionType = config.readNumEntry( "LimitReachedAction", 0 );
194
      mConfigMap.insert( groups[ i ], entry );
195
    }
196
  }
197
}
198
199
void KTrashPropsDlgPlugin::writeConfig()
200
{
201
  TDEConfig config( "ktrashrc" );
202
203
  // first delete all existing groups
204
  const TQStringList groups = config.groupList();
205
  for ( uint i = 0; i < groups.count(); ++i )
206
    if ( groups[ i ].startsWith( "/" ) )
207
      config.deleteGroup( groups[ i ] );
208
209
  TQMapConstIterator<TQString, ConfigEntry> it;
210
  for ( it = mConfigMap.begin(); it != mConfigMap.end(); ++it ) {
211
    config.setGroup( it.key() );
212
    config.writeEntry( "UseTimeLimit", it.data().useTimeLimit );
213
    config.writeEntry( "Days", it.data().days );
214
    config.writeEntry( "UseSizeLimit", it.data().useSizeLimit );
215
    config.writeEntry( "Percent", it.data().percent );
216
    config.writeEntry( "LimitReachedAction", it.data().actionType );
217
  }
218
219
  config.sync();
220
}
221
222
void KTrashPropsDlgPlugin::setupGui( TQFrame *frame )
223
{
224
  TQVBoxLayout *layout = new TQVBoxLayout( frame, 11, 6 );
225
226
  TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
227
  if ( map.count() != 1 ) {
228
    // If we have multiple trashes, we setup a widget to choose
229
    // which trash to configure
230
    TQListBox *mountPoints = new TQListBox( frame );
231
    layout->addWidget( mountPoints );
232
233
    const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon( "folder", TDEIcon::Small );
234
    TQMapConstIterator<int, TQString> it;
235
    for ( it = map.begin(); it != map.end(); ++it ) {
236
      DiscSpaceUtil util( it.data() );
237
      mountPoints->insertItem( folderPixmap, util.mountPoint(), it.key() ); 
238
    }
239
240
    mountPoints->setCurrentItem( 0 );
241
242
    connect( mountPoints, SIGNAL( highlighted( int ) ), SLOT( trashChanged( int ) ) );
243
  } else {
244
    mCurrentTrash = map[0];
245
  }
246
247
  TQHBoxLayout *daysLayout = new TQHBoxLayout( layout );
248
249
  mUseTimeLimit = new TQCheckBox( i18n( "Delete files older than:" ), frame );
250
  daysLayout->addWidget( mUseTimeLimit );
251
  mDays = new TQSpinBox( 1, 365, 1, frame );
252
  mDays->setSuffix( " days" );
253
  daysLayout->addWidget( mDays );
254
255
  TQGridLayout *sizeLayout = new TQGridLayout( layout, 2, 2 );
256
  mUseSizeLimit = new TQCheckBox( i18n( "Limit to maximum size" ), frame );
257
  sizeLayout->addMultiCellWidget( mUseSizeLimit, 0, 0, 0, 1 );
258
259
  mSizeWidget = new TQWidget( frame );
260
  sizeLayout->setColSpacing( 0, 30 );
261
  sizeLayout->addWidget( mSizeWidget, 1, 1 );
262
263
  TQGridLayout *sizeWidgetLayout = new TQGridLayout( mSizeWidget, 2, 3, 11, 6 );
264
265
  TQLabel *label = new TQLabel( i18n( "Maximum Size:" ), mSizeWidget );
266
  sizeWidgetLayout->addWidget( label, 0, 0 );
267
268
  mPercent = new KDoubleSpinBox( 0.001, 100, 1, 10, 3, mSizeWidget );
269
  mPercent->setSuffix( " %" );
270
  sizeWidgetLayout->addWidget( mPercent, 0, 1 );
271
272
  mSizeLabel = new TQLabel( mSizeWidget );
273
  sizeWidgetLayout->addWidget( mSizeLabel, 0, 2 );
274
275
  label = new TQLabel( i18n( "When limit reached:" ), mSizeWidget );
276
  sizeWidgetLayout->addWidget( label, 1, 0 );
277
278
  mLimitReachedAction = new TQComboBox( mSizeWidget );
279
  mLimitReachedAction->insertItem( i18n( "Warn me" ) );
280
  mLimitReachedAction->insertItem( i18n( "Delete oldest files from trash" ) );
281
  mLimitReachedAction->insertItem( i18n( "Delete biggest files from trash" ) );
282
  sizeWidgetLayout->addMultiCellWidget( mLimitReachedAction, 1, 1, 1, 2 );
283
284
  layout->addStretch();
285
}
286
287
#include "ktrashpropsdlgplugin.moc"
(-)tdebase/tdeioslave/trash/ktrashpropsdlgplugin.desktop (+6 lines)
Line 0 Link Here
1
[Desktop Entry]
2
Type=Service
3
Name=Trash Properties Page
4
Name[x-test]=xxTrash Properties Pagexx
5
X-TDE-Library=ktrashpropsdlgplugin
6
ServiceTypes=KPropsDlg/Plugin,application/x-desktop
(-)tdebase/tdeioslave/trash/ktrashpropsdlgplugin.h (+78 lines)
Line 0 Link Here
1
/*
2
   This file is part of the KDE project
3
4
   Copyright (C) 2008 Tobias Koenig <tokoe@kde.org>
5
6
   This library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Library General Public
8
   License as published by the Free Software Foundation; either
9
   version 2 of the License, or (at your option) any later version.
10
11
   This library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Library General Public License for more details.
15
16
   You should have received a copy of the GNU Library General Public License
17
   along with this library; see the file COPYING.LIB.  If not, write to
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
   Boston, MA 02110-1301, USA.
20
*/
21
22
#ifndef KTRASHPROPSDLGPLUGIN_H
23
#define KTRASHPROPSDLGPLUGIN_H
24
25
#include <kpropertiesdialog.h>
26
27
class KDoubleSpinBox;
28
class TQCheckBox;
29
class TQComboBox;
30
class TQFrame;
31
class TQLabel;
32
class TQSpinBox;
33
class TrashImpl;
34
35
class KTrashPropsDlgPlugin : public KPropsDlgPlugin
36
{
37
  Q_OBJECT
38
39
  public:
40
    KTrashPropsDlgPlugin( KPropertiesDialog *dialog, const char*, const TQStringList& );
41
    ~KTrashPropsDlgPlugin();
42
43
    virtual void applyChanges();
44
45
  private slots:
46
    void percentChanged( double );
47
    void trashChanged( int );
48
    void useTypeChanged();
49
50
  private:
51
    void readConfig();
52
    void writeConfig();
53
    void setupGui( TQFrame *frame );
54
55
    TQCheckBox *mUseTimeLimit;
56
    TQSpinBox *mDays;
57
    TQCheckBox *mUseSizeLimit;
58
    TQWidget *mSizeWidget;
59
    KDoubleSpinBox *mPercent;
60
    TQLabel *mSizeLabel;
61
    TQComboBox *mLimitReachedAction;
62
63
    TrashImpl *mTrashImpl;
64
    TQString mCurrentTrash;
65
66
    typedef struct {
67
      bool useTimeLimit;
68
      int days;
69
      bool useSizeLimit;
70
      double percent;
71
      int actionType;
72
    } ConfigEntry;
73
74
    typedef TQMap<TQString, ConfigEntry> ConfigMap;
75
    ConfigMap mConfigMap;
76
};
77
78
#endif
(-)tdebase/tdeioslave/trash/trashimpl.cpp (+95 lines)
Lines 18-23 Link Here
18
*/
18
*/
19
19
20
#include "trashimpl.h"
20
#include "trashimpl.h"
21
#include "discspaceutil.h"
22
21
#include <tdelocale.h>
23
#include <tdelocale.h>
22
#include <klargefile.h>
24
#include <klargefile.h>
23
#include <tdeio/global.h>
25
#include <tdeio/global.h>
Lines 322-327 Link Here
322
bool TrashImpl::moveToTrash( const TQString& origPath, int trashId, const TQString& fileId )
324
bool TrashImpl::moveToTrash( const TQString& origPath, int trashId, const TQString& fileId )
323
{
325
{
324
    kdDebug() << k_funcinfo << endl;
326
    kdDebug() << k_funcinfo << endl;
327
    if ( !adaptTrashSize( origPath, trashId ) )
328
        return false;
329
325
    const TQString dest = filesPath( trashId, fileId );
330
    const TQString dest = filesPath( trashId, fileId );
326
    if ( !move( origPath, dest ) ) {
331
    if ( !move( origPath, dest ) ) {
327
        // Maybe the move failed due to no permissions to delete source.
332
        // Maybe the move failed due to no permissions to delete source.
Lines 387-392 Link Here
387
bool TrashImpl::copyToTrash( const TQString& origPath, int trashId, const TQString& fileId )
392
bool TrashImpl::copyToTrash( const TQString& origPath, int trashId, const TQString& fileId )
388
{
393
{
389
    kdDebug() << k_funcinfo << endl;
394
    kdDebug() << k_funcinfo << endl;
395
    if ( !adaptTrashSize( origPath, trashId ) )
396
        return false;
397
390
    const TQString dest = filesPath( trashId, fileId );
398
    const TQString dest = filesPath( trashId, fileId );
391
    if ( !copy( origPath, dest ) )
399
    if ( !copy( origPath, dest ) )
392
        return false;
400
        return false;
Lines 959-962 Link Here
959
    return true;
967
    return true;
960
}
968
}
961
969
970
bool TrashImpl::adaptTrashSize( const TQString& origPath, int trashId )
971
{
972
    TDEConfig config( "ktrashrc" );
973
974
    const TQString trashPath = trashDirectoryPath( trashId );
975
    config.setGroup( trashPath );
976
977
    bool useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
978
    bool useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
979
    double percent = config.readDoubleNumEntry( "Percent", 10 );
980
    int actionType = config.readNumEntry( "LimitReachedAction", 0 );
981
982
    if ( useTimeLimit ) { // delete all files in trash older than X days
983
        const int maxDays = config.readNumEntry( "Days", 7 );
984
        const TQDateTime currentDate = TQDateTime::currentDateTime();
985
986
        const TrashedFileInfoList trashedFiles = list();
987
        for ( uint i = 0; i < trashedFiles.count(); ++i ) {
988
            struct TrashedFileInfo info = trashedFiles[ i ];
989
            if ( info.trashId != trashId )
990
                continue;
991
992
            if ( info.deletionDate.daysTo( currentDate ) > maxDays )
993
              del( info.trashId, info.fileId );
994
        }
995
996
        return true;
997
998
    }
999
1000
    if ( useSizeLimit ) { // check if size limit exceeded
1001
1002
        // calculate size of the files to be put into the trash
1003
        unsigned long additionalSize = DiscSpaceUtil::sizeOfPath( origPath );
1004
1005
        DiscSpaceUtil util( trashPath + "/files/" );
1006
        if ( util.usage( additionalSize ) >= percent ) {
1007
            if ( actionType == 0 ) { // warn the user only
1008
                m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
1009
                m_lastErrorMessage = i18n( "The trash has reached its maximum size!\nClean the trash manually." );
1010
                return false;
1011
            } else {
1012
                // before we start to remove any files from the trash,
1013
                // check whether the new file will fit into the trash
1014
                // at all...
1015
1016
                unsigned long partitionSize = util.size(); // in kB
1017
                unsigned long fileSize = additionalSize/1024; // convert to kB
1018
1019
                if ( ((double)fileSize*100/(double)partitionSize) >= percent ) {
1020
                    m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
1021
                    m_lastErrorMessage = i18n( "The file is too large to be trashed." );
1022
                    return false;
1023
                }
1024
1025
                // the size of the to be trashed file is ok, so lets start removing
1026
                // some other files from the trash
1027
1028
                TQDir dir( trashPath + "/files" );
1029
                const TQFileInfoList *infos = 0;
1030
                if ( actionType == 1 )  // delete oldest files first
1031
                    infos = dir.entryInfoList( TQDir::Files | TQDir::Dirs, TQDir::Time | TQDir::Reversed );
1032
                else if ( actionType == 2 ) // delete biggest files first
1033
                    infos = dir.entryInfoList( TQDir::Files | TQDir::Dirs, TQDir::Size );
1034
                else
1035
                    tqWarning( "Should never happen!" );
1036
1037
                TQFileInfoListIterator it( *infos );
1038
                TQFileInfo *info;
1039
                bool deleteFurther = true;
1040
                while ( ((info = it.current()) != 0) && deleteFurther ) {
1041
1042
                    if ( info->fileName() != "." && info->fileName() != ".." ) {
1043
                        del( trashId, info->fileName() ); // delete trashed file
1044
1045
                        if ( util.usage( additionalSize ) < percent ) // check whether we have enough space now
1046
                            deleteFurther = false;
1047
                    }
1048
                    ++it;
1049
                }
1050
            }
1051
        }
1052
    }
1053
1054
    return true;
1055
}
1056
962
#include "trashimpl.moc"
1057
#include "trashimpl.moc"
(-)tdebase/tdeioslave/trash/trashimpl.h (+2 lines)
Lines 123-128 Link Here
123
    void fileAdded();
123
    void fileAdded();
124
    void fileRemoved();
124
    void fileRemoved();
125
125
126
    bool adaptTrashSize( const TQString& origPath, int trashId );
127
126
    // Warning, returns error code, not a bool
128
    // Warning, returns error code, not a bool
127
    int testDir( const TQString& name ) const;
129
    int testDir( const TQString& name ) const;
128
    void error( int e, const TQString& s );
130
    void error( int e, const TQString& s );

Return to bug 1923