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 discspaceutil.cpp trashimpl.cpp
56
  LINK 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/tdebase/tdeioslave/trash/CMakeLists.txt~ (+74 lines)
Line 0 Link Here
1
#################################################
2
#
3
#  (C) 2010-2011 Serghei Amelian
4
#  serghei (DOT) amelian (AT) gmail.com
5
#
6
#  Improvements and feedback are welcome
7
#
8
#  This file is released under GPL >= 2
9
#
10
#################################################
11
12
add_subdirectory( tdefile-plugin )
13
14
15
include_directories(
16
  ${CMAKE_CURRENT_BINARY_DIR}
17
  ${TDE_INCLUDE_DIR}
18
  ${TQT_INCLUDE_DIRS}
19
)
20
21
link_directories(
22
  ${TQT_LIBRARY_DIRS}
23
)
24
25
26
##### other data ################################
27
28
install( FILES ktrashpropsdlgplugin.desktop trash.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
29
30
31
##### trashcommon (static) ######################
32
33
set( target trashcommon )
34
35
tde_add_library( ${target} STATIC_PIC AUTOMOC
36
  SOURCES trashimpl.cpp discspaceutil.cpp 
37
)
38
39
40
##### tdeio_trash (module) ########################
41
42
set( target tdeio_trash )
43
44
tde_add_kpart( ${target} AUTOMOC
45
  SOURCES tdeio_trash.cpp
46
  LINK trashcommon-static tdeio-shared
47
  DESTINATION ${PLUGIN_INSTALL_DIR}
48
)
49
50
##### ktrashpropsdlgplugin (module) ########################
51
52
set( target ktrashpropsdlgplugin )
53
54
tde_add_kpart( ${target} AUTOMOC
55
  SOURCES ktrashpropsdlgplugin.cpp discspaceutil.cpp trashimpl.cpp
56
  LINK tdeio-shared
57
  DESTINATION ${PLUGIN_INSTALL_DIR}
58
)
59
60
##### ktrash (executable) #######################
61
62
set( target ktrash )
63
64
tde_add_executable( ${target}
65
  SOURCES ktrash.cpp
66
  LINK tdeio-shared
67
  DESTINATION ${BIN_INSTALL_DIR}
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 (+302 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
  useTypeChanged();
76
77
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
78
           this, SLOT( setDirty() ) );
79
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
80
           this, SLOT( useTypeChanged() ) );
81
  connect( mDays, SIGNAL( valueChanged( int ) ),
82
           this, SLOT( setDirty() ) );
83
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
84
           this, SLOT( setDirty() ) );
85
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
86
           this, SLOT( useTypeChanged() ) );
87
  connect( mPercent, SIGNAL( valueChanged( double ) ),
88
           this, SLOT( percentChanged( double ) ) );
89
  connect( mPercent, SIGNAL( valueChanged( double ) ),
90
           this, SLOT( setDirty() ) );
91
  connect( mLimitReachedAction, SIGNAL( activated( int ) ),
92
           this, SLOT( setDirty() ) );
93
94
//  trashChanged( 0 );
95
    mUseTimeLimit->setChecked( mConfigMap[ mCurrentTrash ].useTimeLimit );
96
    mUseSizeLimit->setChecked( mConfigMap[ mCurrentTrash ].useSizeLimit );
97
    mDays->setValue( mConfigMap[ mCurrentTrash ].days );
98
    mPercent->setValue( mConfigMap[ mCurrentTrash ].percent );
99
    mLimitReachedAction->setCurrentItem( mConfigMap[ mCurrentTrash ].actionType );
100
}
101
102
KTrashPropsDlgPlugin::~KTrashPropsDlgPlugin()
103
{
104
}
105
106
void KTrashPropsDlgPlugin::applyChanges()
107
{
108
  if ( !mCurrentTrash.isEmpty() ) {
109
    ConfigEntry entry;
110
    entry.useTimeLimit = mUseTimeLimit->isChecked();
111
    entry.days = mDays->value();
112
    entry.useSizeLimit = mUseSizeLimit->isChecked();
113
    entry.percent = mPercent->value(),
114
    entry.actionType = mLimitReachedAction->currentItem();
115
    mConfigMap.insert( mCurrentTrash, entry );
116
  }
117
118
  writeConfig();
119
}
120
121
void KTrashPropsDlgPlugin::percentChanged( double percent )
122
{
123
  DiscSpaceUtil util( mCurrentTrash );
124
125
  double partitionSize = util.size() * 1024.0; // convert to byte
126
127
  double size = partitionSize*(percent/100.0);
128
129
  TQString unit = i18n( "Byte" );
130
  if ( size > 1024 ) {
131
    unit = i18n( "KByte" );
132
    size = size/1024.0;
133
  }
134
  if ( size > 1024 ) {
135
    unit = i18n( "MByte" );
136
    size = size/1024.0;
137
  }
138
  if ( size > 1024 ) {
139
    unit = i18n( "GByte" );
140
    size = size/1024.0;
141
  }
142
  if ( size > 1024 ) {
143
    unit = i18n( "TByte" );
144
    size = size/1024.0;
145
  }
146
147
  mSizeLabel->setText( i18n( "(%1 %2)" ).arg( TQString::number( size, 'f', 2 ) ).arg( unit ) );
148
}
149
150
void KTrashPropsDlgPlugin::trashChanged( int value )
151
{
152
  const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
153
154
  if ( !mCurrentTrash.isEmpty() ) {
155
    ConfigEntry entry;
156
    entry.useTimeLimit = mUseTimeLimit->isChecked();
157
    entry.days = mDays->value();
158
    entry.useSizeLimit = mUseSizeLimit->isChecked();
159
    entry.percent = mPercent->value(),
160
    entry.actionType = mLimitReachedAction->currentItem();
161
    mConfigMap.insert( mCurrentTrash, entry );
162
  }
163
164
  mCurrentTrash = map[ value ];
165
166
  if ( mConfigMap.contains( mCurrentTrash ) ) {
167
    const ConfigEntry entry = mConfigMap[ mCurrentTrash ];
168
    mUseTimeLimit->setChecked( entry.useTimeLimit );
169
    mDays->setValue( entry.days );
170
    mUseSizeLimit->setChecked( entry.useSizeLimit );
171
    mPercent->setValue( entry.percent );
172
    mLimitReachedAction->setCurrentItem( entry.actionType );
173
  } else {
174
    mUseTimeLimit->setChecked( false );
175
    mDays->setValue( 7 );
176
    mUseSizeLimit->setChecked( true );
177
    mPercent->setValue( 10.0 );
178
    mLimitReachedAction->setCurrentItem( 0 );
179
  }
180
181
  percentChanged( mPercent->value() );
182
}
183
184
void KTrashPropsDlgPlugin::useTypeChanged()
185
{
186
  mDays->setEnabled( mUseTimeLimit->isChecked() );
187
  mSizeWidget->setEnabled( mUseSizeLimit->isChecked() );
188
}
189
190
void KTrashPropsDlgPlugin::readConfig()
191
{
192
  kdDebug() << "KTrashPropsDlgPlugin::readConfig() called" << endl;
193
  TDEConfig config( "trashrc" );
194
  mConfigMap.clear();
195
196
  const TQStringList groups = config.groupList();
197
  for ( uint i = 0; i < groups.count(); ++i ) {
198
    if ( groups[ i ].startsWith( "/" ) ) {
199
      config.setGroup( groups[ i ] );
200
      ConfigEntry entry;
201
      entry.useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
202
      entry.days = config.readNumEntry( "Days", 7 );
203
      entry.useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
204
      entry.percent = config.readDoubleNumEntry( "Percent", 10 );
205
      entry.actionType = config.readNumEntry( "LimitReachedAction", 0 );
206
      mConfigMap.insert( groups[ i ], entry );
207
    }
208
  }
209
}
210
211
void KTrashPropsDlgPlugin::writeConfig()
212
{
213
  kdDebug() << "KTrashPropsDlgPlugin::writeConfig() called" << endl;
214
  TDEConfig config( "trashrc" );
215
216
  // first delete all existing groups
217
  const TQStringList groups = config.groupList();
218
  for ( uint i = 0; i < groups.count(); ++i )
219
    if ( groups[ i ].startsWith( "/" ) )
220
      config.deleteGroup( groups[ i ] );
221
222
  TQMapConstIterator<TQString, ConfigEntry> it;
223
  for ( it = mConfigMap.begin(); it != mConfigMap.end(); ++it ) {
224
    config.setGroup( it.key() );
225
    config.writeEntry( "UseTimeLimit", it.data().useTimeLimit );
226
    config.writeEntry( "Days", it.data().days );
227
    config.writeEntry( "UseSizeLimit", it.data().useSizeLimit );
228
    config.writeEntry( "Percent", it.data().percent );
229
    config.writeEntry( "LimitReachedAction", it.data().actionType );
230
  }
231
232
  config.sync();
233
}
234
235
void KTrashPropsDlgPlugin::setupGui( TQFrame *frame )
236
{
237
  kdDebug() << "KTrashPropsDlgPlugin::setupGui( TQFrame *frame )" << endl;
238
  TQVBoxLayout *layout = new TQVBoxLayout( frame, 11, 6 );
239
240
  TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
241
  if ( map.count() != 1 ) {
242
    // If we have multiple trashes, we setup a widget to choose
243
    // which trash to configure
244
    TQListBox *mountPoints = new TQListBox( frame );
245
    layout->addWidget( mountPoints );
246
247
    const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon( "folder", TDEIcon::Small );
248
    TQMapConstIterator<int, TQString> it;
249
    for ( it = map.begin(); it != map.end(); ++it ) {
250
      DiscSpaceUtil util( it.data() );
251
      mountPoints->insertItem( folderPixmap, util.mountPoint(), it.key() ); 
252
    }
253
254
    mountPoints->setCurrentItem( 0 );
255
256
    connect( mountPoints, SIGNAL( highlighted( int ) ), SLOT( trashChanged( int ) ) );
257
  } else {
258
    mCurrentTrash = map[0];
259
  }
260
261
  TQHBoxLayout *daysLayout = new TQHBoxLayout( layout );
262
263
  mUseTimeLimit = new TQCheckBox( i18n( "Delete files older than:" ), frame );
264
  daysLayout->addWidget( mUseTimeLimit );
265
  mDays = new TQSpinBox( 1, 365, 1, frame );
266
  mDays->setSuffix( " days" );
267
  daysLayout->addWidget( mDays );
268
269
  TQGridLayout *sizeLayout = new TQGridLayout( layout, 2, 2 );
270
  mUseSizeLimit = new TQCheckBox( i18n( "Limit to maximum size" ), frame );
271
  sizeLayout->addMultiCellWidget( mUseSizeLimit, 0, 0, 0, 1 );
272
273
  mSizeWidget = new TQWidget( frame );
274
  sizeLayout->setColSpacing( 0, 30 );
275
  sizeLayout->addWidget( mSizeWidget, 1, 1 );
276
277
  TQGridLayout *sizeWidgetLayout = new TQGridLayout( mSizeWidget, 2, 3, 11, 6 );
278
279
  TQLabel *label = new TQLabel( i18n( "Maximum Size:" ), mSizeWidget );
280
  sizeWidgetLayout->addWidget( label, 0, 0 );
281
282
  mPercent = new KDoubleSpinBox( 0.001, 100, 1, 10, 3, mSizeWidget );
283
  mPercent->setSuffix( " %" );
284
  sizeWidgetLayout->addWidget( mPercent, 0, 1 );
285
286
  mSizeLabel = new TQLabel( mSizeWidget );
287
  sizeWidgetLayout->addWidget( mSizeLabel, 0, 2 );
288
289
  label = new TQLabel( i18n( "When limit reached:" ), mSizeWidget );
290
  sizeWidgetLayout->addWidget( label, 1, 0 );
291
292
  mLimitReachedAction = new TQComboBox( mSizeWidget );
293
  mLimitReachedAction->insertItem( i18n( "Warn me" ) );
294
  mLimitReachedAction->insertItem( i18n( "Delete oldest files from trash" ) );
295
  mLimitReachedAction->insertItem( i18n( "Delete biggest files from trash" ) );
296
  sizeWidgetLayout->addMultiCellWidget( mLimitReachedAction, 1, 1, 1, 2 );
297
298
  layout->addStretch();
299
300
}
301
302
#include "ktrashpropsdlgplugin.moc"
(-)a/tdebase/tdeioslave/trash/ktrashpropsdlgplugin.cpp~ (+301 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
  useTypeChanged();
76
77
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
78
           this, SLOT( setDirty() ) );
79
  connect( mUseTimeLimit, SIGNAL( toggled( bool ) ),
80
           this, SLOT( useTypeChanged() ) );
81
  connect( mDays, SIGNAL( valueChanged( int ) ),
82
           this, SLOT( setDirty() ) );
83
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
84
           this, SLOT( setDirty() ) );
85
  connect( mUseSizeLimit, SIGNAL( toggled( bool ) ),
86
           this, SLOT( useTypeChanged() ) );
87
  connect( mPercent, SIGNAL( valueChanged( double ) ),
88
           this, SLOT( percentChanged( double ) ) );
89
  connect( mPercent, SIGNAL( valueChanged( double ) ),
90
           this, SLOT( setDirty() ) );
91
  connect( mLimitReachedAction, SIGNAL( activated( int ) ),
92
           this, SLOT( setDirty() ) );
93
94
//  trashChanged( 0 );
95
    mUseTimeLimit->setChecked( mConfigMap[ mCurrentTrash ].useTimeLimit );
96
    mUseSizeLimit->setChecked( mConfigMap[ mCurrentTrash ].useSizeLimit );
97
    mDays->setValue( mConfigMap[ mCurrentTrash ].days );
98
    mPercent->setValue( mConfigMap[ mCurrentTrash ].percent );
99
    mLimitReachedAction->setCurrentItem( mConfigMap[ mCurrentTrash ].actionType );
100
}
101
102
KTrashPropsDlgPlugin::~KTrashPropsDlgPlugin()
103
{
104
}
105
106
void KTrashPropsDlgPlugin::applyChanges()
107
{
108
  if ( !mCurrentTrash.isEmpty() ) {
109
    ConfigEntry entry;
110
    entry.useTimeLimit = mUseTimeLimit->isChecked();
111
    entry.days = mDays->value();
112
    entry.useSizeLimit = mUseSizeLimit->isChecked();
113
    entry.percent = mPercent->value(),
114
    entry.actionType = mLimitReachedAction->currentItem();
115
    mConfigMap.insert( mCurrentTrash, entry );
116
  }
117
118
  writeConfig();
119
}
120
121
void KTrashPropsDlgPlugin::percentChanged( double percent )
122
{
123
  DiscSpaceUtil util( mCurrentTrash );
124
125
  double partitionSize = util.size() * 1024.0; // convert to byte
126
127
  double size = partitionSize*(percent/100.0);
128
129
  TQString unit = i18n( "Byte" );
130
  if ( size > 1024 ) {
131
    unit = i18n( "KByte" );
132
    size = size/1024.0;
133
  }
134
  if ( size > 1024 ) {
135
    unit = i18n( "MByte" );
136
    size = size/1024.0;
137
  }
138
  if ( size > 1024 ) {
139
    unit = i18n( "GByte" );
140
    size = size/1024.0;
141
  }
142
  if ( size > 1024 ) {
143
    unit = i18n( "TByte" );
144
    size = size/1024.0;
145
  }
146
147
  mSizeLabel->setText( i18n( "(%1 %2)" ).arg( TQString::number( size, 'f', 2 ) ).arg( unit ) );
148
}
149
150
void KTrashPropsDlgPlugin::trashChanged( int value )
151
{
152
  const TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
153
154
  if ( !mCurrentTrash.isEmpty() ) {
155
    ConfigEntry entry;
156
    entry.useTimeLimit = mUseTimeLimit->isChecked();
157
    entry.days = mDays->value();
158
    entry.useSizeLimit = mUseSizeLimit->isChecked();
159
    entry.percent = mPercent->value(),
160
    entry.actionType = mLimitReachedAction->currentItem();
161
    mConfigMap.insert( mCurrentTrash, entry );
162
  }
163
164
  mCurrentTrash = map[ value ];
165
166
  if ( mConfigMap.contains( mCurrentTrash ) ) {
167
    const ConfigEntry entry = mConfigMap[ mCurrentTrash ];
168
    mUseTimeLimit->setChecked( entry.useTimeLimit );
169
    mDays->setValue( entry.days );
170
    mUseSizeLimit->setChecked( entry.useSizeLimit );
171
    mPercent->setValue( entry.percent );
172
    mLimitReachedAction->setCurrentItem( entry.actionType );
173
  } else {
174
    mUseTimeLimit->setChecked( false );
175
    mDays->setValue( 7 );
176
    mUseSizeLimit->setChecked( true );
177
    mPercent->setValue( 10.0 );
178
    mLimitReachedAction->setCurrentItem( 0 );
179
  }
180
181
  percentChanged( mPercent->value() );
182
}
183
184
void KTrashPropsDlgPlugin::useTypeChanged()
185
{
186
  mDays->setEnabled( mUseTimeLimit->isChecked() );
187
  mSizeWidget->setEnabled( mUseSizeLimit->isChecked() );
188
}
189
190
void KTrashPropsDlgPlugin::readConfig()
191
{
192
  kdDebug() << "KTrashPropsDlgPlugin::readConfig() called" << endl;
193
  TDEConfig config( "trashrc" );
194
  mConfigMap.clear();
195
196
  const TQStringList groups = config.groupList();
197
  for ( uint i = 0; i < groups.count(); ++i ) {
198
    if ( groups[ i ].startsWith( "/" ) ) {
199
      config.setGroup( groups[ i ] );
200
      ConfigEntry entry;
201
      entry.useTimeLimit = config.readBoolEntry( "UseTimeLimit", false );
202
      entry.days = config.readNumEntry( "Days", 7 );
203
      entry.useSizeLimit = config.readBoolEntry( "UseSizeLimit", true );
204
      entry.percent = config.readDoubleNumEntry( "Percent", 10 );
205
      entry.actionType = config.readNumEntry( "LimitReachedAction", 0 );
206
      mConfigMap.insert( groups[ i ], entry );
207
    }
208
  }
209
}
210
211
void KTrashPropsDlgPlugin::writeConfig()
212
{
213
  kdDebug() << "KTrashPropsDlgPlugin::writeConfig() called" << endl;
214
  TDEConfig config( "trashrc" );
215
216
  // first delete all existing groups
217
  const TQStringList groups = config.groupList();
218
  for ( uint i = 0; i < groups.count(); ++i )
219
    if ( groups[ i ].startsWith( "/" ) )
220
      config.deleteGroup( groups[ i ] );
221
222
  TQMapConstIterator<TQString, ConfigEntry> it;
223
  for ( it = mConfigMap.begin(); it != mConfigMap.end(); ++it ) {
224
    config.setGroup( it.key() );
225
    config.writeEntry( "UseTimeLimit", it.data().useTimeLimit );
226
    config.writeEntry( "Days", it.data().days );
227
    config.writeEntry( "UseSizeLimit", it.data().useSizeLimit );
228
    config.writeEntry( "Percent", it.data().percent );
229
    config.writeEntry( "LimitReachedAction", it.data().actionType );
230
  }
231
232
  config.sync();
233
}
234
235
void KTrashPropsDlgPlugin::setupGui( TQFrame *frame )
236
{
237
  kdDebug() << "KTrashPropsDlgPlugin::setupGui( TQFrame *frame )" << endl;
238
  TQVBoxLayout *layout = new TQVBoxLayout( frame, 11, 6 );
239
240
  TrashImpl::TrashDirMap map = mTrashImpl->trashDirectories();
241
  if ( map.count() != 1 ) {
242
    // If we have multiple trashes, we setup a widget to choose
243
    // which trash to configure
244
    TQListBox *mountPoints = new TQListBox( frame );
245
    layout->addWidget( mountPoints );
246
247
    const TQPixmap folderPixmap = TDEGlobal::iconLoader()->loadIcon( "folder", TDEIcon::Small );
248
    TQMapConstIterator<int, TQString> it;
249
    for ( it = map.begin(); it != map.end(); ++it ) {
250
      DiscSpaceUtil util( it.data() );
251
      mountPoints->insertItem( folderPixmap, util.mountPoint(), it.key() ); 
252
    }
253
254
    mountPoints->setCurrentItem( 0 );
255
256
    connect( mountPoints, SIGNAL( highlighted( int ) ), SLOT( trashChanged( int ) ) );
257
  } else {
258
    mCurrentTrash = map[0];
259
  }
260
261
  TQHBoxLayout *daysLayout = new TQHBoxLayout( layout );
262
263
  mUseTimeLimit = new TQCheckBox( i18n( "Delete files older than:" ), frame );
264
  daysLayout->addWidget( mUseTimeLimit );
265
  mDays = new TQSpinBox( 1, 365, 1, frame );
266
  mDays->setSuffix( " days" );
267
  daysLayout->addWidget( mDays );
268
269
  TQGridLayout *sizeLayout = new TQGridLayout( layout, 2, 2 );
270
  mUseSizeLimit = new TQCheckBox( i18n( "Limit to maximum size" ), frame );
271
  sizeLayout->addMultiCellWidget( mUseSizeLimit, 0, 0, 0, 1 );
272
273
  mSizeWidget = new TQWidget( frame );
274
  sizeLayout->setColSpacing( 0, 30 );
275
  sizeLayout->addWidget( mSizeWidget, 1, 1 );
276
277
  TQGridLayout *sizeWidgetLayout = new TQGridLayout( mSizeWidget, 2, 3, 11, 6 );
278
279
  TQLabel *label = new TQLabel( i18n( "Maximum Size:" ), mSizeWidget );
280
  sizeWidgetLayout->addWidget( label, 0, 0 );
281
282
  mPercent = new KDoubleSpinBox( 0.000, 100, 1, 10, 3, mSizeWidget );
283
  mPercent->setSuffix( " %" );
284
  sizeWidgetLayout->addWidget( mPercent, 0, 1 );
285
286
  mSizeLabel = new TQLabel( mSizeWidget );
287
  sizeWidgetLayout->addWidget( mSizeLabel, 0, 2 );
288
289
  label = new TQLabel( i18n( "When limit reached:" ), mSizeWidget );
290
  sizeWidgetLayout->addWidget( label, 1, 0 );
291
292
  mLimitReachedAction = new TQComboBox( mSizeWidget );
293
  mLimitReachedAction->insertItem( i18n( "Warn me" ) );
294
  mLimitReachedAction->insertItem( i18n( "Delete oldest files from trash" ) );
295
  mLimitReachedAction->insertItem( i18n( "Delete biggest files from trash" ) );
296
  sizeWidgetLayout->addMultiCellWidget( mLimitReachedAction, 1, 1, 1, 2 );
297
298
  layout->addStretch();
299
}
300
301
#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,application/x-trash,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( "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"
(-)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