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

(-)a/tmp/tdebase/tdeioslave/trash/CMakeLists.txt (-2 / +17 lines)
Lines 25-31 link_directories( 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 install( FILES trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} ) 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 47-52 tde_add_kpart( ${target} AUTOMOC Link Here
47
  DESTINATION ${PLUGIN_INSTALL_DIR}
47
  DESTINATION ${PLUGIN_INSTALL_DIR}
48
)
48
)
49
49
50
##### ktrashpropsdlgplugin (module) ########################
51
52
set( target ktrashpropsdlgplugin )
53
54
tde_add_kpart( ${target} AUTOMOC
55
  SOURCES ktrashpropsdlgplugin.cpp
56
  LINK trashcommon-static tdeio-shared
57
  DESTINATION ${PLUGIN_INSTALL_DIR}
58
)
50
59
51
##### ktrash (executable) #######################
60
##### ktrash (executable) #######################
52
61
Lines 57-59 tde_add_executable( ${target} Link Here
57
  LINK tdeio-shared
66
  LINK tdeio-shared
58
  DESTINATION ${BIN_INSTALL_DIR}
67
  DESTINATION ${BIN_INSTALL_DIR}
59
)
68
)
69
70
##### testtrash (executable) #######################
71
tde_add_executable( testtrash
72
  SOURCES testtrash.cpp AUTOMOC
73
  LINK trashcommon-static tdeio-shared
74
)
(-)a/tmp/tdebase/tdeioslave/trash/Makefile.am (-2 / +11 lines)
Lines 3-9 METASOURCES = AUTO 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 ktrash_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $ 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 TESTS = testtrash 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)
(-)a/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"
(-)a/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
(-)a/tdebase/tdeioslave/trash/ktrashpropsdlgplugin.cpp (+316 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
   Copyright (C) 2016 Emanoil Kotsev <deloptes@yahoo.com>
6
7
   This library is free software; you can redistribute it and/or
8
   modify it under the terms of the GNU Library General Public
9
   License as published by the Free Software Foundation; either
10
   version 2 of the License, or (at your option) any later version.
11
12
   This library is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
   Library General Public License for more details.
16
17
   You should have received a copy of the GNU Library General Public License
18
   along with this library; see the file COPYING.LIB.  If not, write to
19
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
   Boston, MA 02110-1301, USA.
21
*/
22
23
#include "ktrashpropsdlgplugin.h"
24
#include "discspaceutil.h"
25
#include "trashimpl.h"
26
27
#include <tqcheckbox.h>
28
#include <tqcombobox.h>
29
#include <tqlabel.h>
30
#include <tqlayout.h>
31
#include <tqlistbox.h>
32
#include <tqspinbox.h>
33
34
#include <kdesktopfile.h>
35
#include <kgenericfactory.h>
36
#include <tdeglobal.h>
37
#include <kiconloader.h>
38
#include <tdelocale.h>
39
#include <knuminput.h>
40
41
#include <kdebug.h>
42
43
typedef KGenericFactory<KTrashPropsDlgPlugin, KPropertiesDialog> Factory;
44
K_EXPORT_COMPONENT_FACTORY( ktrashpropsdlgplugin, Factory( "ktrashpropsdlgplugin" ) )
45
46
KTrashPropsDlgPlugin::KTrashPropsDlgPlugin( KPropertiesDialog *dialog, const char*, const TQStringList& )
47
  : KPropsDlgPlugin( dialog )
48
{
49
  kdDebug() << "KTrashPropsDlgPlugin::KTrashPropsDlgPlugin called" << endl;
50
  if ( dialog->items().count() != 1 )
51
    return;
52
53
  KFileItem *item = dialog->items().first();
54
55
  if ( !KPropsDlgPlugin::isDesktopFile( item ) )
56
    return;
57
58
  kdDebug() << "KPropsDlgPlugin::isDesktopFile( item ) passed" << endl;
59
  KDesktopFile deskFile( item->url().path(), true /* readonly */ );
60
61
  if ( deskFile.readURL() != "trash:/" )
62
    return;
63
64
  kdDebug() << "deskFile.readURL() != \"trash:/\") passed" << endl;
65
  TDEGlobal::locale()->insertCatalogue( "tdeio_trash" );
66
67
  mTrashImpl = new TrashImpl();
68
  mTrashImpl->init();
69
70
  readConfig();
71
72
  TQFrame *frame = dialog->addPage( i18n( "Size Limits" ) );
73
  setupGui( frame );
74
75
76
  mUseTimeLimit->setChecked( mConfigMap[ mCurrentTrash ].useTimeLimit );
77
  mUseSizeLimit->setChecked( mConfigMap[ mCurrentTrash ].useSizeLimit );
78
  mDays->setValue( mConfigMap[ mCurrentTrash ].days );
79
  mPercent->setValue( mConfigMap[ mCurrentTrash ].percent );
80
  mPercent->setPrecision(3);
81
  mLimitReachedAction->setCurrentItem( mConfigMap[ mCurrentTrash ].actionType );
82
  percentChanged(mPercent->value());
83
84
  useTypeChanged();
85
86
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
87
           this, SLOT( setDirty() ) );
88
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
89
           this, SLOT( useTypeChanged() ) );
90
  connect( mDays, SIGNAL( valueChanged( int ) ),
91
           this, SLOT( setDirty() ) );
92
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
93
           this, SLOT( setDirty() ) );
94
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
95
           this, SLOT( useTypeChanged() ) );
96
  connect( mPercent, SIGNAL( valueChanged( double ) ),
97
           this, SLOT( percentChanged( double ) ) );
98
  connect( mPercent, SIGNAL( valueChanged( double ) ),
99
           this, SLOT( setDirty() ) );
100
  connect( mLimitReachedAction, SIGNAL( activated( int ) ),
101
           this, SLOT( setDirty() ) );
102
103
 trashChanged( 0 );
104
}
105
106
KTrashPropsDlgPlugin::~KTrashPropsDlgPlugin()
107
{
108
}
109
110
void KTrashPropsDlgPlugin::applyChanges()
111
{
112
  if ( !mCurrentTrash.isEmpty() ) {
113
    ConfigEntry entry;
114
    entry.useTimeLimit = mUseTimeLimit->isChecked();
115
    entry.days = mDays->value();
116
    entry.useSizeLimit = mUseSizeLimit->isChecked();
117
    entry.percent = mPercent->value(),
118
    entry.actionType = mLimitReachedAction->currentItem();
119
    mConfigMap.insert( mCurrentTrash, entry );
120
  }
121
122
  writeConfig();
123
}
124
125
void KTrashPropsDlgPlugin::percentChanged( double percent )
126
{
127
  DiscSpaceUtil util( mCurrentTrash );
128
129
  double partitionSize = util.size() * 1024.0; // convert to byte
130
131
  double size = partitionSize*(percent/100.0);
132
133
// Step should be depending on size
134
// https://api.kde.org/3.5-api/kdelibs-apidocs/kdeui/html/classKDoubleSpinBox.html
135
// https://api.kde.org/3.5-api/kdelibs-apidocs/kdeui/html/knuminput_8cpp_source.html
136
  mPercent->setPrecision(3);
137
138
  TQString unit = i18n( "Byte" );
139
  if ( size > 1024 ) {
140
    unit = i18n( "KByte" );
141
    size = size/1024.0;
142
    mPercent->setLineStep(0.001);
143
  }
144
  if ( size > 1024 ) {
145
    unit = i18n( "MByte" );
146
    size = size/1024.0;
147
    mPercent->setLineStep(0.01);
148
  }
149
  if ( size > 1024 ) {
150
    unit = i18n( "GByte" );
151
    size = size/1024.0;
152
    mPercent->setLineStep(0.1);
153
  }
154
  if ( size > 1024 ) {
155
    unit = i18n( "TByte" );
156
    size = size/1024.0;
157
    mPercent->setLineStep(1);
158
  }
159
160
  mSizeLabel->setText( i18n( "(%1 %2)" ).arg( TQString::number( size, 'f', 2 ) ).arg( unit ) );
161
162
}
163
164
void KTrashPropsDlgPlugin::trashChanged( int value )
165
{
166
  const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
167
168
  if ( !mCurrentTrash.isEmpty() ) {
169
    ConfigEntry entry;
170
    entry.useTimeLimit = mUseTimeLimit->isChecked();
171
    entry.days = mDays->value();
172
    entry.useSizeLimit = mUseSizeLimit->isChecked();
173
    entry.percent = mPercent->value(),
174
    entry.actionType = mLimitReachedAction->currentItem();
175
    mConfigMap.insert( mCurrentTrash, entry );
176
  }
177
178
  mCurrentTrash = map[ value ];
179
180
  if ( mConfigMap.contains( mCurrentTrash ) ) {
181
    const ConfigEntry entry = mConfigMap[ mCurrentTrash ];
182
    mUseTimeLimit->setChecked( entry.useTimeLimit );
183
    mDays->setValue( entry.days );
184
    mUseSizeLimit->setChecked( entry.useSizeLimit );
185
    mPercent->setValue( entry.percent );
186
    mLimitReachedAction->setCurrentItem( entry.actionType );
187
  } else {
188
    mUseTimeLimit->setChecked( false );
189
    mDays->setValue( 7 );
190
    mUseSizeLimit->setChecked( true );
191
    mPercent->setValue( 10.0 );
192
    mLimitReachedAction->setCurrentItem( 0 );
193
  }
194
195
  percentChanged( mPercent->value() );
196
}
197
198
void KTrashPropsDlgPlugin::useTypeChanged()
199
{
200
  mDays->setEnabled( mUseTimeLimit->isChecked() );
201
  mSizeWidget->setEnabled( mUseSizeLimit->isChecked() );
202
}
203
204
void KTrashPropsDlgPlugin::readConfig()
205
{
206
  kdDebug() << "KTrashPropsDlgPlugin::readConfig() called" << endl;
207
  TDEConfig config( "trashrc" );
208
  mConfigMap.clear();
209
210
  const TQStringList groups = config.groupList();
211
  for ( uint i = 0; i < groups.count(); ++i ) {
212
    if ( groups[ i ].startsWith( "/" ) ) {
213
      config.setGroup( groups[ i ] );
214
      ConfigEntry entry;
215
      entry.useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
216
      entry.days = config.readNumEntry( "Days", 7 );
217
      entry.useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
218
      entry.percent = config.readDoubleNumEntry( "Percent", 10 );
219
      entry.actionType = config.readNumEntry( "LimitReachedAction", 0 );
220
      mConfigMap.insert( groups[ i ], entry );
221
    }
222
  }
223
}
224
225
void KTrashPropsDlgPlugin::writeConfig()
226
{
227
  kdDebug() << "KTrashPropsDlgPlugin::writeConfig() called" << endl;
228
  TDEConfig config( "trashrc" );
229
230
  // first delete all existing groups
231
  const TQStringList groups = config.groupList();
232
  for ( uint i = 0; i < groups.count(); ++i )
233
    if ( groups[ i ].startsWith( "/" ) )
234
      config.deleteGroup( groups[ i ] );
235
236
  TQMapConstIterator<TQString, ConfigEntry> it;
237
  for ( it = mConfigMap.begin(); it != mConfigMap.end(); ++it ) {
238
    config.setGroup( it.key() );
239
    config.writeEntry( "UseTimeLimit", it.data().useTimeLimit );
240
    config.writeEntry( "Days", it.data().days );
241
    config.writeEntry( "UseSizeLimit", it.data().useSizeLimit );
242
    config.writeEntry( "Percent", it.data().percent );
243
    config.writeEntry( "LimitReachedAction", it.data().actionType );
244
  }
245
246
  config.sync();
247
}
248
249
void KTrashPropsDlgPlugin::setupGui( TQFrame *frame )
250
{
251
  kdDebug() << "KTrashPropsDlgPlugin::setupGui( TQFrame *frame )" << endl;
252
  TQVBoxLayout *layout = new TQVBoxLayout( frame, 11, 6 );
253
254
  TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
255
  if ( map.count() != 1 ) {
256
    // If we have multiple trashes, we setup a widget to choose
257
    // which trash to configure
258
    TQListBox *mountPoints = new TQListBox( frame );
259
    layout->addWidget( mountPoints );
260
261
    const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon( "folder", TDEIcon::Small );
262
    TQMapConstIterator<int, TQString> it;
263
    for ( it = map.begin(); it != map.end(); ++it ) {
264
      DiscSpaceUtil util( it.data() );
265
      mountPoints->insertItem( folderPixmap, util.mountPoint(), it.key() ); 
266
    }
267
268
    mountPoints->setCurrentItem( 0 );
269
270
    connect( mountPoints, SIGNAL( highlighted( int ) ), SLOT( trashChanged( int ) ) );
271
  } else {
272
    mCurrentTrash = map[0];
273
  }
274
275
  TQHBoxLayout *daysLayout = new TQHBoxLayout( layout );
276
277
  mUseTimeLimit = new TQCheckBox( i18n( "Delete files older than:" ), frame );
278
  daysLayout->addWidget( mUseTimeLimit );
279
  mDays = new TQSpinBox( 1, 365, 1, frame );
280
  mDays->setSuffix( " days" );
281
  daysLayout->addWidget( mDays );
282
283
  TQGridLayout *sizeLayout = new TQGridLayout( layout, 2, 2 );
284
  mUseSizeLimit = new TQCheckBox( i18n( "Limit to maximum size" ), frame );
285
  sizeLayout->addMultiCellWidget( mUseSizeLimit, 0, 0, 0, 1 );
286
287
  mSizeWidget = new TQWidget( frame );
288
  sizeLayout->setColSpacing( 0, 30 );
289
  sizeLayout->addWidget( mSizeWidget, 1, 1 );
290
291
  TQGridLayout *sizeWidgetLayout = new TQGridLayout( mSizeWidget, 2, 3, 11, 6 );
292
293
  TQLabel *label = new TQLabel( i18n( "Maximum Size:" ), mSizeWidget );
294
  sizeWidgetLayout->addWidget( label, 0, 0 );
295
296
  mPercent = new KDoubleSpinBox( 0.001, 100, 1, 10, 3, mSizeWidget );
297
  mPercent->setSuffix( " %" );
298
  sizeWidgetLayout->addWidget( mPercent, 0, 1 );
299
300
  mSizeLabel = new TQLabel( mSizeWidget );
301
  sizeWidgetLayout->addWidget( mSizeLabel, 0, 2 );
302
303
  label = new TQLabel( i18n( "When limit reached:" ), mSizeWidget );
304
  sizeWidgetLayout->addWidget( label, 1, 0 );
305
306
  mLimitReachedAction = new TQComboBox( mSizeWidget );
307
  mLimitReachedAction->insertItem( i18n( "Warn me" ) );
308
  mLimitReachedAction->insertItem( i18n( "Delete oldest files from trash" ) );
309
  mLimitReachedAction->insertItem( i18n( "Delete biggest files from trash" ) );
310
  sizeWidgetLayout->addMultiCellWidget( mLimitReachedAction, 1, 1, 1, 2 );
311
312
  layout->addStretch();
313
314
}
315
316
#include "ktrashpropsdlgplugin.moc"
(-)a/tdebase/tdeioslave/trash/ktrashpropsdlgplugin.desktop (+6 lines)
Line 0 Link Here
1
[Desktop Entry]
2
Type=Service
3
Name=Trash Properties Page
4
Name[bg]=Свойства на кошчето
5
X-TDE-Library=ktrashpropsdlgplugin
6
X-TDE-ServiceTypes=KPropsDlg/Plugin,media/builtin-trash
(-)a/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
(-)a/tmp/tdebase/tdeioslave/trash/testtrash.cpp (-1 / +1 lines)
Lines 24-30 Link Here
24
#include "tdeio_trash.h"
24
#include "tdeio_trash.h"
25
#include "testtrash.h"
25
#include "testtrash.h"
26
26
27
#include <config.h>
27
// #include <config.h>
28
28
29
#include <kurl.h>
29
#include <kurl.h>
30
#include <tdelocale.h>
30
#include <tdelocale.h>
(-)a/tmp/tdebase/tdeioslave/trash/trash.protocol (-1 / +1 lines)
Lines 86-89 ExtraNames[vi]=Đường dẫn Trước khi vứt,Ngày Vứt Link Here
86
ExtraNames[wa]=Oridjinå tchmin,Date di disfaçaedje
86
ExtraNames[wa]=Oridjinå tchmin,Date di disfaçaedje
87
ExtraNames[zh_CN]=原始路径,删除日期
87
ExtraNames[zh_CN]=原始路径,删除日期
88
ExtraNames[zh_TW]=原始路徑,刪除日期
88
ExtraNames[zh_TW]=原始路徑,刪除日期
89
ExtraTypes=QString,QDateTime
89
ExtraTypes=TQString,TQDateTime
(-)a/tmp/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 bool TrashImpl::deleteInfo( int trashId, const TQString& fileId ) 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 void TrashImpl::jobFinished(TDEIO::Job* job) 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 bool TrashImpl::parseURL( const KURL& url, int& trashId, TQString& fileId, TQStr 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( "trashrc" );
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"
(-)a/tmp/tdebase/tdeioslave/trash/trashimpl.h (+2 lines)
Lines 123-128 private: 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